The #id selector selects the element with the specific id from id attribute.
The id attribute must be unique within a document.
$("#id")
Parameter | Optional | Description |
---|---|---|
id | Required. | the id of the element to select |
Select the element with the id "intro":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#intro").css("background-color", "yellow"); });//from w ww. j a v a 2 s .c o m </script> </head> <body> <h1>Welcome to My Homepage</h1> <p id="intro">This is a test.</p> <p>I am from java2s.com.</p> </body> </html>