Get the text content of an element

Get the combined text contents of an element, including its descendants, or set the text content of the element.


Use the element property textContent (IE 8: innerText) for getting the content of an element and its descendants, stripped of all HTML tags:

var el = document.querySelector('div');
text = el.textContent || el.innerText;
console.log(text);

Feedback