jQuery focus() trigger focus event

Description

jQuery focus() trigger focus event

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from w w w  .jav  a  2 s  .com
<script>
$(document).ready(function(){
  $("#btn1").click(function(){
    $("input").focus();
    $("p").html("focus event triggered");
  });
  $("#btn2").click(function(){
    $("input").blur();
    $("p").html("blur event triggered");
  });
});
</script>
</head>
<body>

Enter your name: <input type="text">
<br><br>

<button id="btn1">Trigger focus event</button>
<button id="btn2">Trigger blur event</button>

<p style="color:red"></p>

</body>
</html>



PreviousNext

Related