Recently I have been involved in modifying websites with a module that allows for CSS and JS insertion. A bothersome issue that has arisen a few times is the fact that this tool doesn’t currently provide a way to remove the text nodes of just the targeted element. Fortunately, I may soon have access to modify the module to add this capability. Here is a simplified version of the code that I plan on using:
function removeTextNodes(elem) {
var child, i = 0;
while(child = elem.childNodes[i]) {
if(child.nodeType === 3) {
target.removeChild(child);
}
else {
i++;
}
}
}
Believe it or not, it is as simple as that. Here is an example JSBin page which illustrates this fact:
JS Bin