HTML id attribute
Examples
Through the use of JavaScript to handle a text id attribute:
<Head>
<Script type = "text / javascript">
function displayResult ()
{
document.getElementById ( "myHeader") innerHTML = "Have a nice day!".;
}
</ Script>
</ Head>
<Body>
<H1 id = "myHeader"> Hello World! </ H1>
<Button onclick = "displayResult ()"> Change text </ button>
</ Body>
</ Html>
try it"
The bottom section contains more instances.
Browser Support
All major browsers support the id attribute
Definition and Usage
id attribute specifies a unique id HTML elements.
id in the HTML document must be unique.
id attribute can be used as the link anchor (link anchor), through JavaScript (HTML DOM) or changed or added by CSS style for the element with the given id.
Differences between HTML 4.01 and HTML5
In HTML5, id attribute can be used with any HTML element (it will verify that any HTML element, but not necessarily useful).
In HTML 4.01, id attribute can not be used: <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.
Note: HTML 4.01 for the value of id, there are strict limits (for example: in HTML 4.01 id value can not start with a number).
grammar
Property Value
value | description |
---|---|
id | The only element of the specified id. Naming rules:
|
More examples |
Id attribute in CSS
How to use the id attribute for the element in CSS to style
HTML Global Attributes