jQuery focus() Method - CodingTag

jQuery focus()


  • The focus event of jQuery occurs when an HTML element gets focus. This event most often generated by the mouse click or we can also generate it by keyboard key pressing.
  • The focus() method is used to handle the focus event means this method is used to trigger the focus event or attaches a function to run when a focus event occurs.
  • This method is complimentary of the blur() jQuery method and most of the time both functions are used together.

Related Topics:

jQuery unbind
jQuery bind

jQuery focus()




If you want to trigger a function in it, the syntax will be:


Parameter description:

  • function: It represents the function to run when the focus event occurs. It is optional.


<title> jQuery Example </title>
<script type = "text/javascript"
$(".name").attr("placeholder","In blur mode.");
$(".name").attr("placeholder","in focus mode");

<h2> jQuery Focus Event Example </h2>
Name: <input class="name" type="text" name="fullname">
<button class="wr"> Make focus </button>
<button class="nwr"> Make blur </button>


When clicking on the Make focus button,

When clicking on the Make blur button,

Best WordPress Hosting


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price

Leave a Reply

    Waiting for your comments