The textContent returns the text content of all elements.
The innerText returns the content of all elements, except for <script> and <style> elements.
The innerText does not return the text of elements that are hidden with CSS.
The textContent does return the text of elements that are hidden with CSS.
<!DOCTYPE html> <html> <body> <p id="demo">This p element contains a <span style="display:none">hidden span element</span> and a <span>visible span element</span>. </p>/*from w w w.j ava 2s .com*/ <button onclick="getTextContent()">Get textContent</button> <button onclick="getInnerText()">Get innerText</button> <p id="demo"></p> <script> function getTextContent() { document.getElementById("demo").innerHTML = document.getElementById("demo").textContent; } function getInnerText() { document.getElementById("demo").innerHTML = document.getElementById("demo").innerText; } </script> </body> </html>