- 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.
If you want to trigger a function in it, the syntax will be:
- function: It represents the function to run when the focus event occurs. It is optional.
<title> jQuery Example </title>
$(".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,