English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The focusin event occurs when an element (or any element within it) gains focus.
The focusin() method adds the function to be executed when a focus event occurs on an element or any element within it.
Withfocus()The methods are different, the focusin() method will also trigger whether any child element has gained focus.
This method is usually used withfocusout()Methods can be used together.
Trigger the focusin event of the selected element:
$(selector).focusin()
Attach a function to the focusin event:
$(selector).focusin(function)
Trigger the focusin event of <input>:
$(document).ready(function(){ $("input").focusin().css("background-color", "lightgreen"); });Test and see‹/›
Set the background color of the <div> element when the <div> element or any of its child elements gain focus:
$("div").focusin(function(){ $(this).css("background-color", "lightblue"); });Test and see‹/›
Parameters | Description |
---|---|
function | Function executed each time the focusin event is triggered |