![]() |
The JavaScript can access an element with a specific id with the |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h2>Using The id Attribute in JavaScript</h2>
<p>JavaScript can access an element with a specified id by using the getElementById() method:</p>
<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>
What is HTML id Attribute | HTML id Attribute |
How to Use HTML id Attribute | HTML id Attribute |
What are the Difference Between HTML Class and ID | HTML id Attribute |
How to create HTML Bookmarks with ID and Links (Jump to Specific Text) | HTML id Attribute |
How to use The id Attribute in JavaScript | HTML id Attribute |
Full Example of The id Attribute in JavaScript | HTML id Attribute |
Read Full: | HTML id Attribute |
Category: | Web Tutorial |
Sub Category: | HTML id Attribute |
Uploaded: | 1 year ago |
Uploaded by: | Admin |
Views: | 56 |
Reffered: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_id_js