Is there a way to get innerText of only the top element (and ignore the child element\'s innerText) ?
Example:
top node text
<
tagName attribute, then it's an element: Remove the node.innerText to get the textual contents (with fallback to textContent, when innerText is not supported).Code:
var elem = document.getElementById('theelement');
elem = elem.cloneNode(true);
for (var i=elem.childNodes.length-1; i>=0; i--) {
if (elem.childNodes[i].tagName) elem.removeChild(elem.childNodes[i]);
}
var innerText = elem['innerText' in elem ? 'innerText' : 'textContent'];