jQuery blur()

The jQuery blur() event triggers the blur (element loses focus) event.

Syntax:

To trigger the blur event.

$(selector).blur()

To add a function to the blur event.

$(selector).blur(function)

Function: It is an optional parameter that is used to specify the function to run after the event occurs.

Example1:

<!DOCTYPE html>
<html>
head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$("input").blur(function(){
alert("This text box has lost its focus.");
});
});
</script>
</head>
<body>
Enter your name: <input type="text">
</body>
</html>

Example2:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
("input").blur(function(){
$(this).css("background-color", "#ffffff");
});
});
</script>
</head>
<body>
Name: <input type="text" name="fullname"><br>
Email: <input type="text" name="email">
</body>
</html>