Skip to content

Instantly share code, notes, and snippets.

@sanjaytj
Created April 5, 2021 08:38
Show Gist options
  • Save sanjaytj/98fe1388b910acdfefe952a4b849109a to your computer and use it in GitHub Desktop.
Save sanjaytj/98fe1388b910acdfefe952a4b849109a to your computer and use it in GitHub Desktop.
<p id="demo"> This element has extra spacing and contains <span>a span element</span>.</p>
<button onclick="getInnerText()">Get innerText</button>
<button onclick="getHTML()">Get innerHTML</button>
<button onclick="getTextContent()">Get textContent</button>
<p id="demo"></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