Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If there is "onselectstart", is there "onselectend"?

The JavaScript DOM Event onselectstart fires before the selection is changed. What if I wanted to get the new selection, check if this new selection isCollapsed? I'll explain a little further: the user selects content on the page, firing the selectstart event; but if one wanted to see what selection did the user select, the event would still pick the selection that existed before the user fired the event...(that might be more confusing..)

Example scenario:

<div id="content">Some filler paragraph</div>

And JS:

//content is handle for div#content
// I'm not worrying about cross-compat here (.attachEvent)...
content.addEventHandler("selectstart",function(){
   var nes=document.getSelection();
   if(nes.isCollapsed){
     // Do something
   }
});
like image 239
JCOC611 Avatar asked Oct 13 '22 17:10

JCOC611


1 Answers

You may try handling the "mouseup" event and examining the current selection.

like image 177
Alexander Pavlov Avatar answered Dec 12 '22 11:12

Alexander Pavlov