Is there a way to get innerText of only the top element (and ignore the child element\'s innerText) ?
Example:
top node text
<
If you don't want to ignore the child element's inner text, use the following function:
function getInnerText(el) {
var x = [];
var child = el.firstChild;
while (child) {
if (child.nodeType == 3) {
x.push(child.nodeValue);
}
else if (child.nodeType == 1) {
var ii = getInnerText(child);
if (ii.length > 0) x.push(ii);
}
child = child.nextSibling;
}
return x.join(" ");
}