is there a jquery selector for text that is highlighted after its dragged over by the mouse cursor? For example, I want to select text that I’ve typed into my textarea field, click a button, which puts <p> tags around the text I’ve highlighted with my mouse cursor. A non-plugin solution would be preferred, thanks.
is there a jquery selector for text that is highlighted after its dragged over
Share
There’s a straight up javascript solution that’s pretty nice… just use
inputElement.selectionStartandinputElement.selectionEnd.It’s helpful to note that this is just on Dom elements, so you’ll have to take your jQuery selector for your textarea and add [0] to get the element itself, ie.
$("#myTextArea")[0].selectionStart.From there you can do some string work and add in your
<p>tags at the appropriate indexes.I haven’t tested this, but it should work…