You probably want to try textContent instead of innerHTML .
This innerHTML will return the contents of the DOM as a String , not just text in a div . This is good if you know that your div contains only text, but does not fit if each use case. For these cases, you probably have to use textContent instead of innerHTML
For example, given the following markup:
<div id="test"> Some <span class="foo">sample</span> text. </div>
You will get the following result:
var node = document.getElementById('test'), htmlContent = node.innerHTML, // htmlContent = "Some <span class="foo">sample</span> text." textContent = node.textContent; // textContent = "Some sample text."
See MDN for more details:
dhar Apr 29 '12 at 11:30 2012-04-29 11:30
source share