Created
April 5, 2021 08:24
-
-
Save sanjaytj/6d48d3b181481be0ca78dfcca068fc10 to your computer and use it in GitHub Desktop.
Subtle differences between innerText, innerHTML and textContent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p id="demo"> This element has extra spacing and contains <span>a span element</span>.</p> | |
<script> | |
function getInnerText() { | |
alert(document.getElementById("demo").innerText) | |
} | |
function getHTML() { | |
alert(document.getElementById("demo").innerHTML) | |
} | |
function getTextContent() { | |
alert(document.getElementById("demo").textContent) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment