javascript get text from div code example
Example: javascript get text from div
You'll probably want to try textContent instead of innerHTML.
Given innerHTML will return DOM content as a String and not exclusively the "text" in the div. It's fine if you know that your div contains only text but not suitable if every use case. For those cases, you'll probably have to use textContent instead of innerHTML
For example, considering the following markup:
Some sample text.
You'll get the following result:
var node = document.getElementById('test'),
htmlContent = node.innerHTML,
// htmlContent = "Some sample text."
textContent = node.textContent;
// textContent = "Some sample text."