Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to distinguish between click and selection?

I have a div with a hidden child. Clicking in the div will toggle the visibility of the child. This works well.

Now the user wants to select some text in the child. Dragging the selection works but as soon as the mouse button is released, the div closes (because of the inClick handler).

If possible, I'd still like to be able to close the div from anywhere in the child because the child can be quite large (hundreds of lines, so it would be tedious to scroll to the div to toggle the child).

Needs to work with IE6+ and all sane browsers. I can't use jQuery directly :-( but I can copy code from jQuery so if jQuery had a solution, I clone it.

Suggestions?

like image 366
Aaron Digulla Avatar asked Oct 28 '25 12:10

Aaron Digulla


1 Answers

You can do a check on window.getSelection() to see if it contains anything before closing your inner div.

For IE6 you'll want to substitute this with document.selection.

Note that this is proprietry to IE so you'll want to distinguish which method to use via object detection.

Working Demo

like image 168
Jamie Dixon Avatar answered Oct 30 '25 01:10

Jamie Dixon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!