Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

innerText vs textContent

// textContent gets the content of all elements, including <script> and <style> elements.
// textContent returns every element in the node.
// innerText only shows “human-readable” elements.
// innerText looks at styling and won't return the text of “hidden” elements.

<style>
.special { display: none; }
</style>
<h1>Heading <span class="special">Special</span> </h1>

const h1 = document.querySelector('h1');
console.debug(h1.textContent); // " Heading Special "
console.debug(h1.innerText); // "Heading"
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #innerText #textContent
ADD COMMENT
Topic
Name
5+5 =