I'm working on a project which is doing some DOM tree walking. In order to insert some span tags to add highlights to a document, it is sometimes necessary to split a textnode:
var newTextNode = treeWalker.currentNode.splitText(charOffset);
The issue is then when I next try to call:
if (newTextNode.nodeValue == "")
{
//...
}
This .nodeValue
call yields a JavaScript error in IE9 which says simply, Incorrect function.
Wholly unhelpful to say the least. Thinking perhaps something weird is going on, I opened up the debugger and executed: typeof newTextNode.nodeValue
which returns "unknown"
.
Is anyone able to explain this behavior? I thought maybe that function simply doesn't apply to text nodes, but it works just fine in other scenarios. It's only after calling splitText
that it seems to puke.
I thank everyone for their help! My Google-fu has been thus far insufficient.
ADDITION:
After looking at the newTextNode object, there's more properties that evaluate to "Incorrect Function"
- data
- length
- nodeValue
- textContent
- wholeText