Accessing HTML tag in JavaScript

by | Dec 25, 2020 | JavaScript

Home » Website Development » JavaScript » Accessing HTML tag in JavaScript

Accessing HTML tag in JavaScript

To dynamically change the content of our webpage, we will have to access an HTML tag. It can be easily achieved by finding an HTML tag with its element ID. Thus, we will also have to assign an ID to the HTML tag for which we want to change the content using JavaScript. This will be clearer from the example mentioned below:

document.getElementById("idH2").innerHTML = "Hello India";


In the above example, we search for an element by its ID in the whole HTML document and then replace its inner HTML content with the text in the right side of equal to sign (=), here “Hello India”.


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.