Reputation: 85
I have discovered a double-click problem in IE.
The following is my HTML:
<div id="test">Hello World!</div>
And my jQuery:
$('#test').bind('dblclick', function (event) {
event.stopPropagation();
$(this).css({'background-color': 'red'});
});
In IE, do the following:
The DIV turns red, as if the double-click event originated in the DIV.
It seems that in IE the double-click event is fired both when the double-click:
Yet in FF/Chrome the event is fired only when the double click STARTS and ENDS inside the DIV.
What is the official explanation for this? And how can I make IE double-clicks behave like FF/Chrome double-clicks?
Upvotes: 3
Views: 6995
Reputation: 11716
Here's a fiddle. jQuery's dblclick
works for me on both FF and IE9. Tested: "the event is fired only when the double click STARTS and ENDS inside the DIV"
$("#test").dblclick(function(event) {
event.stopPropagation();
$(this).css({'background-color': 'red'});
});
Upvotes: 0
Reputation: 74420
(on)dblclick event is a native javascript event, not a jquery's event
Dblclick event is not consistent across browsers, see this ticket 3 years old but still valid in some way: http://bugs.jquery.com/ticket/7876 even now sequence in IE10 is the same as FF/Chrome/Safari but as you noted it, there are still some bugs.
As a workaround, you could use this snippet instead of dblclick event:
$('#test').on('click', function(event){
var t = this;
if (!t.clicks) t.clicks = 0;
++t.clicks;
if (t.clicks === 2) {
t.clicks = 0;
//here the kind of dclclick is fired ...
$(t).css({'background-color' : "red"});
}
setTimeout(function () {
t.clicks = 0
}, 500);//duration value can be change depending of your wishes
});
An other workaround could be to bind/unbind dblclick event on mousedown/mouseenter/mouseleave (hover) handlers, like that:
DEMO with mousedown/mouseenter/mouseleave
$('#test').hover(function () {
$(this).on('mousedown.cust', function () {
$(this).on('dblclick.cust', function () {
$(this).css({
'background-color': "red"
});
});
});
}, function () {
$(this).off('mousedown.cust dblclick.cust');
});
Upvotes: 5