How to remove highlight with this function?

Ok so I found an interesting code which removes the highlight when you click on the body, but it also removes that highlighted word with it. How to prevent that? Here’s the code:


Sounds contraindicating. Why would you want to remove the class from the element but also keep it?

@stetim94 actually I figured it out. I changed the 2nd part $('highlight') to $('body'), and that did it. It does not keep it. What’s happening here is that the highlight from the text is being removed when you click on the body.

.remove() will remove the whole element from the DOM, is that desired?

No, just the highlight.

If i look at the documentation, I see the following:

we can see that the whole elements gets removed from the DOM. Which is why I am very confused by what you are saying. Are you sure you understand the function you are using?


@stetim94 right, I understand how that’s working.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.