The innerText
property returns the actual text value of an html element while the innerHTML
returns the HTML content
. Example below:
var element = document.getElementById('hello');_x000D_
element.innerText = '<strong> hello world </strong>';_x000D_
console.log('The innerText property will not parse the html tags as html tags but as normal text:\n' + element.innerText);_x000D_
_x000D_
console.log('The innerHTML element property will encode the html tags found inside the text of the element:\n' + element.innerHTML);_x000D_
element.innerHTML = '<strong> hello world </strong>';_x000D_
console.log('The <strong> tag we put above has been parsed using the innerHTML property so the .innerText will not show them \n ' + element.innerText);_x000D_
console.log(element.innerHTML);
_x000D_
<p id="hello"> Hello world _x000D_
</p>
_x000D_