jQuery blur()

Introduction

Attach a function to the blur event.

The blur event occurs when the <input> field loses focus:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*w  w  w . j av a 2s.  co  m*/
<script>
$(document).ready(function(){
  $("input").blur(function(){
    document.getElementById("demo").innerHTML = 
            "This input field has lost its focus.";
  });
});
</script>
</head>
<body>

<p id="demo"></p>
Enter your name: <input type="text">
<p>Write something in the input field, and then click 
outside the field to lose focus (blur).</p>

</body>
</html>

The blur event occurs when an element loses focus.

The blur() method triggers the blur event.

The blur() method can also run a function when a blur event occurs.

Trigger the blur event for the selected elements:

$(selector).blur()

Attach a function to the blur event:

$(selector).blur(function)
Parameter Optional Description
function Optional. function to run when the blur event occurs



PreviousNext

Related