Im wondering how I would get the text of a nested list item without getting the text of its children i.e.
-
I want t
The following will get you a concatenated string of all the text nodes that are direct children of a node:
function getChildText(node) {
var text = "";
for (var child = node.firstChild; !!child; child = child.nextSibling) {
if (child.nodeType === 3) {
text += child.nodeValue;
}
}
return text;
}
alert( getChildText(document.getElementById("node")) );