jQuery | focusout() with Example

The focusout() is an inbuilt method in jQuery which is used to remove focus from the selected element.
Syntax:

$(selector).focusout(function);

Parameter: It accepts a parameter “function” which is to be executed after execution of fadeout method.
Return Value: It returns the selected element which loses its focus.
jQuery code to show the working of focusout() method:

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
  
<head>
    <script 
    </script>
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function() {
            $("div").focusin(function() {
                $(this).css("background-color", "green");
            });
            $("div").focusout(function() {
                $(this).css("background-color", "#FFFFFF");
            });
        });
    </script>
    <style>
        div {
            border: 2px solid black;
            width: 50%;
            padding: 20px;
        }
          
        input {
            padding: 5px;
            margin: 10px;
        }
    </style>
</head>
  
<body>
    <!-- click inside the field focusin will take place and when 
                      click outside focusout will take place -->
    <div>
        Enter name:
        <input type="text">
        <br>
    </div>
  
</body>
  
</html>

chevron_right


Output:
After clicking inside of the input field focusin will be in action-



After clicking outside of the input field focusout will be in action.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.