In my Backbone View, I have defined events like this:
JavaScript
x
16
16
1
events : {
2
'click .elm' : 'select',
3
'dblclick .elm' : 'toggle'
4
5
},
6
7
select: function(e){
8
e.preventDefault();
9
console.log('single clicked');
10
}
11
12
toggle : function(e){
13
e.preventDefault();
14
console.log('double clicked');
15
}
16
I have bound single and double click event listeners to same element .elm
. When I double click on this element, I get this output:
single clicked
single clicked
double clicked
Tried preventDefault()
and stopImmediatePropagation()
and that didn’t solve the issue.
So, how can I prevent the single click event getting fired when I double click?
Advertisement
Answer
This isn’t an issue with Backbone itself. It’s about how to handle both single click and double click events on the same button.
See
Update: But it would be better if you didn’t have to deal with it. See mu is too short’s answer below!