You can use innerHTML
(then parse text from HTML) or use innerText
.
let textContentWithHTMLTags = document.querySelector('div').innerHTML;
let textContent = document.querySelector('div').innerText;
console.log(textContentWithHTMLTags, textContent);
innerHTML
and innerText
is supported by all browser(except FireFox < 44) including IE6.