How do I cancel a text selection after the initial mousedown event?

Posted by cwillu-gmail on Stack Overflow See other posts from Stack Overflow or by cwillu-gmail
Published on 2008-09-22T08:10:56Z Indexed on 2010/05/31 14:03 UTC
Read the original article Hit count: 167

Filed under:
|
|

I'm trying to implement a pop-up menu based on a click-and-hold, positioned so that a (really) slow click will still trigger the default action, and with the delay set so that a text-selection gesture won't usually trigger the menu.

What I can't seem to do is cancel the text-selection in a way that doesn't prevent text-selection in the first place: returning false from the event handler (or calling $(this).preventDefault()) prevents the user from selecting at all, and the obvious $().trigger('mouseup') doesn't doesn't do anything with the selection at all.

  • This is in the general context of a page, not particular to a textarea or other text field.
  • e.stopPropogation() doesn't cancel text-selection.
  • I'm not looking to prevent text selections, but rather to veto them after some short period of time, if certain conditions are met.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery