jQuery Tutorial Tutorials - jQuery .blur() method

jQuery .blur() method

The .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.

jQuery .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.

jQuery .blur() method Example

example

Trigger the blur event on all paragraphs:

$("p").blur();

example

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();
});

Try now

Date:2019-08-29 19:05:49 From:www.Lautturi.com author:Lautturi