Javascript examples for jQuery Selector:id
The #id selector selects the element by id.
Parameter | Description |
---|---|
id | Required. id of the element to select |
The following code shows how to select the element with the id "test":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#test").css("background-color", "red"); });/*from w ww.j av a2 s . c o m*/ </script> </head> <body> <p id="test">This is a test.</p> <h1>Welcome to My Homepage</h1> <p id="test">This is a test.</p> <p>This is a paragraph.</p> </body> </html>