Computers & ProgrammingFrontend DevelopmentjQuery

jQuery Blur Event

The jQuery event blur() method triggers when an element loses focus. The blur() method triggers the blur event, or it can specify a function to run when a blur event occurs.

Originally, this event was only applicable to form elements, such as <input>. In modern browsers, the domain of the event has been extended to include all element types. An element can lose focus via keyboard commands or by mouse clicks elsewhere on the page.

Syntax

$(selector).blur()
$(selector).blur(function)
ParameterDescription
functionOptional. Function to run when the event occurs.

Example

$("input").blur(function () {
    $("input").css("background-color", "#666666");
});

In the jQuery code listed above, the blur() method specifies that a function should run when the blur event occurs. In the example above, the input element’s background-color property will be changed when it loses focus.

Leave a Comment

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

Scroll to Top