Say I have a webpage with many instances like of ( | ) scattered all over a certain HTML structure:
Text 1 ( | )
Text 2
Text 3 ( | )
Text 4 ( | )
Text 5
...
...
... ( | )
...
How could I “brutally” delete all the ( | ) from all elements whatsoever in the webpage?
Just one command which runs on all elements and for each element deletes this specific part of the textContent.
There was a typo there as replacAll instead replaceAll, so I fixed it and ran the code but I got:
Uncaught SyntaxError: Invalid or unexpected token
I think that it didn’t work because any of these characters ( and | and ) appears in various parts on each paragraph in the <div> (which I have already deleted with CSS display: none;)
Indeed, just replacing the inner HTML of a parent element would be destructive with regard to event listeners and DOM references on the page. Using a tree walker OTOH you can replace the text node content only, keeping the element nodes and their possible references: