Skip to content
Advertisement

How to remove Highlight () from a paragraph using Javascript

I have HTML where some paragraphs contain <mark> elements. This causes the text within the <mark> element to be highlighted. Essentially, I want to remove the highlight by removing the <mark> element but keeping the textContent.

What’s the best way to do this?

Here’s an example paragraph:

Example with highlighted text

I want to remove the highlighted text. The HTML contains <span> and other elements and some <mark> elements that I don’t want removed. The ones I want removed have a class of .show-mark. I know how to find just the <mark> elements that I want to remove but I don’t know how to remove them.

Here’s the HTML for the example paragraph:

JavaScript

Thanks for your help.

Advertisement

Answer

Try something like this

JavaScript

and see if it works.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement