mir3z / texthighlighter

-- NO LONGER MAINTAINED -- TextHighlighter allows you to highlight text on web pages.
http://mir3z.github.com/texthighlighter/
MIT License
230 stars 101 forks source link

Is there a way to remove a highlight from a selection instead a whole element? #11

Closed ghost closed 9 years ago

ghost commented 9 years ago

I'm trying to unmark a single selection but removeHighlights removes all the highlights.

mir3z commented 9 years ago

There is no such functionality right now. You can only remove highlight(s) from a given element (http://mir3z.github.io/texthighlighter/doc/TextHighlighter.html#removeHighlights). However, you are more than welcome to implement this by yourself and then request a pull.

vinniejames commented 7 years ago

This took me a while to figure out as well, since I was trying to use .click(), which doesn't add listeners to nodes that don't exist yet.

The solution was to use .on() instead:

$(document.body).on('click','.highlighted', function(e){
    hltr.removeHighlights(e.target);
});