Skip to content

Instantly share code, notes, and snippets.

@sanjaytj
Created April 5, 2021 08:24
Show Gist options
  • Save sanjaytj/6d48d3b181481be0ca78dfcca068fc10 to your computer and use it in GitHub Desktop.
Save sanjaytj/6d48d3b181481be0ca78dfcca068fc10 to your computer and use it in GitHub Desktop.
Subtle differences between innerText, innerHTML and textContent
<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