For example :
<span id=1>this is my </span><span id=2>selected text</span><span id=3> but this is not selected</span>
I want to catch the list of span id of the text selected by user with jquery.
In this example i want : [1,2]
thanks
For example :
<span id=1>this is my </span><span id=2>selected text</span><span id=3> but this is not selected</span>
I want to catch the list of span id of the text selected by user with jquery.
In this example i want : [1,2]
thanks
$(window.getSelection().getRangeAt(0).cloneContents()).children("span")
will get you the selected spans. The MDC docs are always a good place to start for this kind of this.
var delimitedList = '';
$('pre span').each(function() {
delimitedList += $(this).attr('id') + ',';
});
//Remove last comma
delimitedList = delimitedList.substring(0, delimitedList.length - 1)
Maybe you can add a class to the spans that are supposed to be selected, like so -
<span id="1" class="selected">this is my </span><span id="2" class="selected">selected text</span><span id=3> but this is not selected</span>
And then use following jQuery -
var selectedByUser = $("span.selected");