focusin() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:focusin

Description

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.

Syntax

$(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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials