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.
In the below code, a function is passed to this method.
Before the mouse clicking inside of the input field-
After the mouse clicking inside of the input field with text “GeeksforGeeks”-
In the below code, no parameter is passed to this method.
Before the mouse is clicked inside of the input field-
After the mouse is clicked inside of the input field with text “GeeksforGeeks”-
- jQuery | :focus Selector
- JQuery | Set focus on a form input text field on page load
- How to select all on focus in input using JQuery?
- How to find which DOM element has the focus using jQuery?
- jQuery lose focus event
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery | prepend() with Examples
- jQuery | dblclick() with Examples
- jQuery | offset() with Examples
- jQuery | children() with Examples
- jQuery | Hide/Show, Toggle and Fading methods with Examples
- jQuery | focusin() with Examples
- jQuery | Animation, Slide methods with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.