In all elements, I want to change any “abc” to “xyz” anywhere (case insensitively); i.e. without caring about what’s coming before it or after it, so for example, 1abc1 would still be changed to 1xyz1 and אבגabcאבג would still be changed to אבגxyzאבג).
Ahoj @bendqh1, if you open the browser console you’ll see an
Uncaught TypeError: element.replace is not a function
This is because querySelectorAll() returns a NodeList, and nodes again don’t have a replace() method. You might replace the textContent though like so:
const walker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT
)
let node
while ((node = walker.nextNode())) {
node.textContent = node.textContent.replace('a', 'b')
}
Glad I could help… which comma operator are you referring to though? The comma after document.body just separates the arguments passed to createTreeWalker(), where the first is the root node from which to start walking, and the second is a bitmask what to show (we only want to operate on text nodes, since modifying the text content of HTML elements will also “flatten” their markup if they have child elements).