I have this basic code to handle all text nodes:
function walk (node) {
if (node.nodeType == '3') {
handleText (node)
}
node = node.firstChild
while (node) {
walk (node)
node = node.nextSibling
}
}
Unfortunately, this handles all text nodes, including elements such as <script>
and <style>
, which I do not want. I updated to my code to the following to ignore these specific elements:
function walk (node) {
if (node.nodeType == '3' && node.tagName != 'SCRIPT' && node.tagName != 'STYLE') {
handleText (node)
}
node = node.firstChild
while (node) {
walk (node)
node = node.nextSibling
}
}
However, this is not working. What am I doing wrong?