0

Let's say I have some text with the class .a and some more text with the class .b.

How to unselect only text with the class .a on mousemove, instead of all text like in this fiddle:

http://jsfiddle.net/Lx5bbrk2/

$('*').mousemove(function(){
    document.getSelection().removeAllRanges(); //deselects all text, needs to be modified
});

I don't know how to put selector into this.

note: select text with ctrl+a or with double click.

edit:

nevermind spans. this fiddle is just a quick illustration. real situation is simple - different text classes are in different divs.

different classes are also different element types - spans and contenteditable divs. doesn't really matter how certain text gets deselected, as long as it's not the whole document.

So is this even possible?

astx123
  • 85
  • 8
  • What behavior would you like if the selection is like [element of class `b`][element of class `a`][element of class `b`]? Do you want to end up with two selections for each of the elements of class `b` (generally browsers don't support this)? – arghbleargh Aug 23 '14 at 19:41
  • I don't have this kind of situation, fiddle with spans is just for simple illustration. Basically, .a is actually a class of contenteditable divs which I want to exclude from deselecting. – astx123 Aug 23 '14 at 19:45
  • so different text classes are in separate divs. simple situation but I can't find the solution. – astx123 Aug 23 '14 at 19:53
  • It sounds like what you want to do on mousemove is something like the following: 1) check what is currently selected, recording elements that are not of class `a`, 2) deselect everything, 3) re-select the recorded elements (i.e. those not of class `a`). I don't remember the details of how to do this at the moment though. – arghbleargh Aug 23 '14 at 20:17

0 Answers0