Search code examples
javascriptjquerytextpluginshighlight

Javascript to select/highlight multiple parts of a text


Is there any easy way or plugin to allow users to select (with their mouse) multiple parts of a text on my page?

I know that using window.getSelection().toString() I can get the current selection, but I'd like to allow the user to highlight multiple parts of the text and be able to know what pieces they highlighted.

Something like the picture below: enter image description here

The general idea is to allow the users to create keywords/key expressions directly from the text


Solution

  • Found one that does exactly what I want (+it's compatible with really old browsers) https://github.com/mir3z/texthighlighter