.blur()
methodThe .blur()
method in jQuery is used to run a function when the matched element loses the focus
or trigger an blur
event on an element.
.blur()
method Syntax.blur() .blur(handler) .blur(eventData,handler)
Parameter | Type | Description |
---|---|---|
handler |
Function | A function to execute when the blur is triggered on the matched element. |
eventData |
Anything | Additional data passed to the event handler. |
.blur()
method ExampleTrigger the blur event on all paragraphs:
$("p").blur();
When the input field loses the focus, execute the event handle function.
When user click the button,Trigger an blur
event on the input
elemetns.
HTML
<form> <input type="text" value="username"> <input type="text" value="email"> </form> <button>Trigger blur event</button>
$( "input" ).blur(function() { console.log("The input box "+$(this).val() +" loses the focus! ") console.log("Handler for .blur() called."); }); $('button').click(function(){ $( "input" ).blur(); });