The :focus Selector is used to select all the elements that have focus on the document currently. It is also used with a tag name or using another selector.
Syntax:
$(":focus")
Example:
<!DOCTYPE html> <html> <head> <script src= </script> <script> $(document).ready(function() { $("input").focus(); $(":focus").css( "background-color", "green"); }); </script> </head> <body> <center> <h1 style="color:green;"> GeeksForGeeks </h1> <h2> jQuery :focus Selector </h2> Name: <input type="text" /> <br> Password: <input type="text" /> <br> <button>Submit </button> </center> </body> </html> |
chevron_right
filter_none
Output:

Supported Browsers: The browser supported by jQuery :focus Selector are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- CSS | :focus Selector
- Difference between :focus and :active selector
- CSS :focus-within Selector
- jQuery | focus() with Examples
- 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 | :input Selector
- jQuery | :nth-of-type() Selector
- jQuery | :enabled Selector
- jQuery | element Selector
- jQuery | :last Selector
- jQuery | :button Selector
- jQuery | animated Selector with Example
- jQuery | :header Selector
- jQuery | #id Selector
- jQuery | .class Selector
- jQuery | :text Selector
- jQuery | :password Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.
Improved By : shubham_singh

