-->

jQuery blur() Method

By: Bipin C Mathew 9 months ago

The Blur is a Jquery Event Method. It occur when elements loses there focus. We can use blur with focus method. This event was commonly used only for elements of the form such as <input>. It has been expanded to include all types of elements in recent browsers.

Syntax
$(selector).blur()  - Trigger the blur event for the selected elements.

$(selector).blur(function) - Attach a function to the blur event.

Example

	<!doctype html>
	<html lang="en">
		<head>
			<meta charset="utf-8">
			<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
			<script>  
				$(document).ready(function(){  
				    $("input").blur(function(){  
					alert("This text box has lost its focus.");  
				    });  
				});  
			</script>   
		</head>
		<body>

			Enter any value: <input type="text">  

		</body>
	</html>

Describtion
In this code jquery is started with $(document).ready(function() . It is used to identify Document Object Model (DOM) is ready for JavaScript code to execute. The $("input").blur(function() function help to add blur method in all input fields. When we click outside the textbox we got an alert"This text box has lost its focus".

Comments

Let us talk!

We take the vision which comes from dreams and apply the magic of science and mathematics, adding the heritage of our profession and our knowledge to create a design.