Description: Bind an event handler to the "blur" JavaScript event, or trigger that event on an element.
.blur( handler(eventObject) )
.blur( )
.blur( [ eventData ], handler(eventObject) )
This method is a shortcut for .bind('blur', handler) in the first variation, and .trigger('blur') in the second.
The blur event is sent to an element when it loses focus. Originally, this event was only applicable to form elements, such as <input>. In recent browsers, the domain of the event has been extended to include all element types. An element can lose focus via keyboard commands, such as the Tab key, or by mouse clicks elsewhere on the page.
For example, consider the HTML:
<form>
<input id="target" type="text" value="Field 1" />
<input type="text" value="Field 2" />
</form>
<div id="other">
Trigger the handler
</div>
The event handler can be bound to the first input field:
$('#target').blur(function() {
alert('Handler for .blur() called.');
});
Handler for .blur() called.
$('#other').click(function() {
$('#target').blur();
});
After this code executes, clicks on Trigger the handler will also alert the message.
The blur event does not bubble in Internet Explorer. Therefore, scripts that rely on event delegation with the blur event will not work consistently across browsers.
Example 1
To trigger the blur event on all paragraphs:$("p").blur();
Example 2
Fire blur.Example 2 - Full source:
Fire blur.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$("input").blur(function () {
$(this).next("span").css('display','inline').fadeOut(1000);
});
});
</script>
<style>span {display:none;}</style>
</head>
<body>
<p><input type="text" /> <span>blur fire</span></p>
<p><input type="password" /> <span>blur fire</span></p>
</body>
</html>

