jQuery Blur Event Trigger Example

In this tutorial, you will learn about jQuery blur event with example. And as well as how to use the jQuery blur event method with HTML elements.

jQuery Blur Event Method

The jQuery blur event occurs when an element loses focus. This can happen uniquely through tab navigation or mouse interactions, including clicks anywhere on the page.

Syntax of jQuery Blur Event Method

$(selector).blur()  

This triggers the blur event for the selected elements.

$(selector).blur(function)  

Parameters of jQuery blur() events Method

ParameterDescription
FunctionIt is an optional parameter. It is used to specify the function to run when the element loses the focus (blur).

Examples of jQuery blur() Event Method

Let’s take first example for demonstrate jQuery blur(); as shown below:

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.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>

Let’s take second example for demonstrate jQuery blur(); as shown below:

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$(document).ready(function(){
 $( "#field1" ).blur(function() {
  alert( "Lose focus from Field1" );
});
});
</script>
  <meta charset="utf-8">
  <title>jQuery: Attach a function to the blur event</title>
</head>
<body>
<form>
<input id="field1" type="text" value="First Field">
<input id="field2" type="text" value="Second Field">
</form>
  <p>Write something in the input First Field, and then click outside the field to check lose focus.</p>
</body>
</html>

The jQuery events (handler) method is used to bind an event handler to a “blur” javascript event, or an event that is triggered.

Recommended jQuery Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *