Richard Hedges
Richard Hedges

Reputation: 1188

jQuery's 'click' function when user highlights text?

I'm using jQuery's click function to check the formatting of highlighted text, however the function isn't always called.

If you highlight part of a line it will work as expected, however if you highlight the entire line it simple doesn't call at all.

Here is a JSFiddle for you to try it out: http://jsfiddle.net/ZMYRH/

Is there any chance I'm using this function incorrectly? Or is there a workaround to what I want to achieve?

Upvotes: 1

Views: 63

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337560

The issue is because a click event is only fired if the mousedown and mouseup event occur on the same element.

In your case the mouseup event would be more appropriate as it will allow the user to drag a selection across elements.

Updated fiddle

Upvotes: 2

Related Questions