Remove a character anywhere in a document

Primarily for the sake of learning and improving my understanding of JavaScript’s mechanics I seek a way to delete one character, wherever it is in a webpage.

Anywhere that this character would appear — in the start of a line, in the end of a line, inside a word, outside a word ------ it would be utterly deleted.

This character could be anything I choose: A letter, a number, a special sign, and I’ll delete any occurrence of it by one simple “brute force” deletion operation.

What would be a good way for that?

I’m no JS expert, so will let others come up with an answer. But as a point of clarity which may direct someone’s preferred solution, let’s say the web page contains the following:

<div>
  <p>hello world</p>
</div>

Could you list what you would expect to see from the code if you asked it to remove the character “d”?

1 Like

The expected output is:

Hello worl

So removing “d” should only happen within text fields, not within html tags, attributes, styling, image names, etc, correct?

In short, yes,
In long, text fields of elements (textContent), but also pseudo elements (in a rare case that there are).

As this is a self imposed hypothetical learning exercise, what would you learn by having someone else find the solution.
You have not shown any attempt at solving this yourself so no one can show you where you go wrong.

I might learn a pattern.

I have yet to find a why which I find clear to do that hence I ask.

There are other open posts which have all the information you need to do this.