Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

textcontent vs innertext in JS

You can forgot all the points that may confuse you but remember 3 things:

When you are trying to alter the text, textContent is usually the property you are looking for.
When you are trying to grab text from some element, innerText approximates the text the user would get if they highlighted the contents of the element with the cursor and then copied to the clipboard. And textContent gives you everything, visible or hidden, including <script> and <style> elements.

In element nodes, innerText evaluates <br> elements, while textContent evaluates control characters:
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #textcontent #innertext #JS
ADD COMMENT
Topic
Name
3+5 =