The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Detect selected text Re: Detect selected text


I’m sorry, it wasn’t what I was looking for. I’ll try to explain again.

If you got a <p> tag with text and you want to copy the part in the middle of it to word. You first select it and then pres ctrl+c. I want to add a class to the selected area of the text. The one that gets a blue background (orange in css-tricks).

Is there a way to do that, add a class to a area that doesn’t have it’s own tag originally.

My idea is to add a <span class="selected"> tag to the start of the selected area and a </span> tag at the end.