.focus() (metodo jQuery) si attiva quando l’Elemento cui acceda guadagna il focus. Per il suo opposto, v. il metodo jQuery .blur().
tips&tricks
La differenza con il metodo jQuery .focusin() consiste nel fatto che quest’ultimo si attiva anche se il focus è guadagnato da un discendente dell’Elemento cui acceda.
Sintassi
/* 1 */
$(selettore).focus()
/* 2 */
$(selettore).focus(function() {
// azione
})
| parametro | descrizione |
|---|---|
| function | La funzione da eseguire quando si verifica l’evento |
Esempi
<script>
$("input").focus(function(){
$(this).css("background-color", "green");
});
$("input").blur(function(){
$(this).css("background-color", "yellow");
});
</script>
<p>Clicca prima su uno e poi sull'altro input:</p>
<input value="UNO">
<input value="DUE">
Contenuti correlati
- CSS
- HTML
- JavaScript
- jQuery
- PHP
- SQL
- WORDPRESS
0 Comment