Javascript innertext code example

Example 1: js inner text

document.getElementById("text").innerText = "Your new text here"

Example 2: change innertext javascript

element.innerText = "Hello World";

Example 3: HTML DOM innerText

var x = document.getElementById("myBtn").innerText;

Example 4: innertext vs innerhtml

Inner text below. It inject string as it is into the element.
My name is <b class="name">Raj Yadav</b>.

Inner html below. It renders the string into the element and treat as part of html document.
My name is Raj Yadav.