Javascript examples for jQuery Method and Property:focusin
The focusin() method sets event handler for focus event on the element or any elements inside it.
focusin() method triggers when any child elements get focus.
$(selector).focusin(function);
Parameter | Require | Description |
---|---|---|
function | Required. | function to run when the focusin event occurs. |
The following code shows how to set background color of a <div> element when the <div> element or any child elements get focus:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("div").focusin(function(){ $(this).css("background-color", "#FFFFCC"); });/*from w ww . j av a 2 s.c o m*/ $("div").focusout(function(){ $(this).css("background-color", "#FFFFFF"); }); }); </script> </head> <body> <p>Input your name</p> <div style="border: 1px solid black;padding:10px;"> First name: <input type="text"><br> Last name: <input type="text"> </div> </body> </html>