jQuery text() method doesn't work on textNodes:
$('div').contents().filter(function(){
return this.nodeType === 3;
}).text("new text");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>
textNode text doesn't change
</div>
My question is what could be the reason for that?
Is this regarding withespace text nodes hard to handle? And/or deeper level descendant text nodes than only children ones?
I'm not asking how to change it, i know workarounds but why jq text()
method doesn't support text nodes? I'd expect using this method on any text node being able to change its node value.
I'm quite sure there is a good reason for that, i cannot just getting it.