jQuery focusIn: Main Tips
- The jQuery
.focusIn()
attaches an event handler to focusIn event. - It differs from .focus() method since
.focusIn()
supports event bubbling.
Usage of .focusIn() Method
A focusin
event occurs when an element gets focus. The jQuery .focusIn()
function adds an event handler to that event, invoked when the specified item or its children receive focus.
In the jQuery focusin example below, an input field changes color when you select it by clicking:
Tip: focusin jQuery is preferred over the jQuery .focus() function when the handler needs to apply to all of the elements inside the selected element.
To specify a function to be run when the specified element or its children are selected, follow this syntax:
$("selector").focusin(function)
You can add a selector and specify the function to be executed.