jQuery | #id Selector

The #id selector specifies an id for an element to be selected. It should not begin with a number and the id attribute must be unique within a document which means it can be used only one time.

Syntax:

$("#id")

Parameter:



  • id: An element’s specific id.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script src=
  </script>
     
  <script>
    $(document).ready(function() {
    $("#Geeks").css("background-color","red");
      });
  </script>
</head>
  
<body>
  
    <h1>GEEKS FOR GEEKS</h1>
  
    <p id="Geeks">jQuery|#id selector
  </p>
  
</body>
  
</html>

chevron_right


Output:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <title>ID</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            float: left;
            padding: 10px;
            margin: 10px;
            background-color: pink;
        }
    </style>
    <script src=
  </script>
</head>
  
<body>
  
    <div id="DIV1">
        <p>id="DIV1"</p>
    </div>
    <div id="DIV2">id="DIV2"</div>
  
    <script>
        $("#DIV2").css("border",
                       "2px solid yellow");
    </script>
  
</body>
  
</html>

chevron_right


Output:

Supported Browsers:

  • Google Chrome
  • Mozilla Firefox
  • Edge
  • Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.