jQuery | focus() with Examples
The focus() is an inbuilt method in jQuery which is used to focus on an element. The element get focused by the mouse click or by the tab-navigating button.
Here selector is the selected element.
Parameter: It accepts an optional parameter “function” which specifies the function to run when the focus event occurs.
Return Value: It returns the selected element which get focused.
jQuery code to show the working of focus() method:
Code #1: In the below code, a function is passed to this method.
Output: Before the mouse clicking inside of the input field-
After the mouse clicking inside of the input field with text “GeeksforGeeks”-
Code #2: In the below code, no parameter is passed to this method.
Output: Before the mouse is clicked inside of the input field-
After the mouse is clicked inside of the input field with text “GeeksforGeeks”-