Javascript examples for jQuery Method and Property:focus
Trigger the focus event for selected elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("input").focus(); $("p").html("focus event triggered"); });/*from ww w .jav a2 s . c o m*/ $("#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>