DOM properties


1. innerHTML property

The innerHTML property is used to write the dynamic html on the html document.

Syntax:

    document.getElementById(“id”).innerHTML = “new HTML”;


Example: The following example changes the content of the paragraph tag to “New Paragraph”.

    <p id=”p1”>Paragraph</p>
    <script>
        document.getElementById(“p1”).innerHTML = “New Paragraph”;
    </script>    



2. innerText property

The innerText property is used to write the dynamic text on the html document.

Syntax:

    document.getElementById(“id”).innerText = “new text”;


Example: The following example changes the text of the paragraph tag to “New text message”.

    <p id=”p1”>Text message</p>
    <script>
        document.getElementById(“p1”).innerText = “New text message”;
    </script>