.blur()


.blur( handler )Возвращает: jQuery

Описание: Bind an event handler to the "blur" JavaScript event, or trigger that event on an element.

  • Добавлен в версии: 1.0.blur( handler )

    • handler
      Тип: Function( Event eventObject )
      A function to execute each time the event is triggered.
  • Добавлен в версии: 1.4.3.blur( [eventData ], handler )

    • eventData
      Тип: Anything
      An object containing data that will be passed to the event handler.
    • handler
      Тип: Function( Event eventObject )
      A function to execute each time the event is triggered.
  • Добавлен в версии: 1.0.blur()

    • This signature does not accept any arguments.

This method is a shortcut for .on( "blur", handler ) in the first two variations, and .trigger( "blur" ) in the third.

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:

1
2
3
4
5
6
7
8
9
10
11
<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." );
});

Now if the first field has the focus, clicking elsewhere or tabbing away from it displays the alert:

Handler for .blur() called.

To trigger the event programmatically, apply .blur() without an argument:

1
2
3
$( "#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. As of version 1.4.2, however, jQuery works around this limitation by mapping blur to the focusout event in its event delegation methods, .live() and .delegate().

Дополнительные замечания:

  • As the .blur() method is just a shorthand for .on( "blur", handler ), detaching is possible using .off( "blur" ).

Example:

To trigger the blur event on all paragraphs:

1
$( "p" ).blur();