I have a piece of code which allows to remove text from child nodes like this:
$.fn.removeText = function() {
for (var i=this.length-1; i>=0; --i) removeText(this[i]);
};
function removeText(node) {
if (!node) return;
for (var i=node.childNodes.length-1; i>=0; --i) {
var childNode = node.childNodes[i];
if (childNode.nodeType === 3) node.removeChild(childNode);
else if (childNode.nodeType === 1) removeText(childNode);
}
}
$('body').removeText();
So now I'm trying to exclude elements, for instance the span like this:
$('body:not(span)').removeText();
It's not working, everything is getting removed. I tried several other (Jquery) things with no luck. Do I have to alter the removeText()
function? I really would like to stick to Jquery..Is there something else I can try?