HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document)."
The id
attribute specifies a unique id for an HTML element (the
value must be unique within the HTML document).
The id
attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to
manipulate the element with the specific id.
The id
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | id |
Use the id attribute to manipulate text with JavaScript:
<html>
<body>
<h1 id="myHeader">Hello World!</h1>
<button onclick="displayResult()">Change text</button>
<script>
function displayResult()
{
document.getElementById("myHeader").innerHTML = "Have a nice day!";
}
</script>
</body>
</html>
Attribute | |||||
---|---|---|---|---|---|
id | Yes | Yes | Yes | Yes | Yes |