Skip to content
Related Articles

Related Articles

Improve Article

jQuery | :focus Selector

  • Last Updated : 15 Apr, 2019
Geek Week

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>

Output:

Supported Browsers: The browser supported by jQuery :focus Selector are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari
My Personal Notes arrow_drop_up
Recommended Articles
Page :