Home >>jQuery Tutorial >jQuery focusout() Method

jQuery focusout() Method

jQuery focusout() Method

jQuery focusout() method in jQuery is used to run a add function when a focusout event occurs on the element, or any elements inside it.

Syntax:
$(selector).focusout(function)

Parameter Values

Parameter Description
function It is optional parameter and is used to specifies the function to run when the focusout event occurs
Here is an Example of jQuery focusout() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".box1").focusin(function(){
$(this).css("background-color", "orange");
});
$(".box1").focusout(function(){
$(this).css("background-color", "#FFFFFF");
});
});
</script>
</head>
<body>
<div class="box1" style="border: 1px solid black;padding:10px;">
Fname: <input type="text"><br>
Lname: <input type="text">
</div>
<p>Click in above input field to get focus and click outside an input field to lose focus.</p>
</body>
</html>

Output:
Fname:
Lname:

Click in above input field to get focus and click outside an input field to lose focus.