Get the id of an element:
The result of x will be:
More "Try it Yourself" examples below.
The id property sets or returns the id of an element (the value of an element's id attribute).
An ID should be unique within a page, and is often returned by using the document.getElementById() method.
Return the id property:
Set the id property:
Value | Description |
---|---|
id | Specifies the id of an element |
Return Value: | A String, representing the ID of an element |
---|
Property | |||||
---|---|---|---|---|---|
id | Yes | Yes | Yes | Yes | Yes |
Change the id of an element:
If the first <div> element in the document has an id of "myDIV", change its font-size:
CSS Tutorial: CSS Selectors
CSS Reference: CSS #id Selector
HTML DOM Reference: HTML DOM getElementById() Method