Open In App
Related Articles

jQuery blur() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

jQuery blur() is an inbuilt method that is used to remove focus from the selected element. This method starts the blur event or it can be attached a function to run when a blur event occurs. 

Syntax:

$(selector).blur(function)

Parameters:

It accepts an optional parameter “function”. 

jQuery examples to show the working of blur() function:

Example 1: In the below code, no function is passed to the blur method. 

HTML

<!DOCTYPE html>
<html>
 
<head>
    <script src=
    </script>
 
    <script>
        $(document).ready(function () {
            $("#btn").click(function () {
                $("input").blur();
                $("p").html(
                    "This is blur method that is used!!!");
            });
        });
    </script>
</head>
 
<body>
    <!--enter value and click on the button -->
    Enter Value:
    <input type="text">
    <br><br>
 
    <button id="btn">
        start blur event!!!
    </button>
    <p style="color:green"></p>
</body>
 
</html>

                    

Output: 

Example 2: In the below code, function is passed to the blur method. 

HTML

<!DOCTYPE html>
<html>
   
<head>
    <script src=
      </script>
   
    <script>
        <!--jQuery code to show blur method-->
            $(document).ready(function () {
                $("input").blur(function () {
                    $(this).css("background-color", "#ADFF2F");
                });
            });
    </script>
</head>
   
<body>
    <!-- Enter a value to the field and click outside
        to see the change -->
    Enter Value:
    <input type="text" name="fullname">
</body>
   
</html>

                    

Output: 


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Last Updated : 11 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials