How do I cancel single click event when double click event fires?
I have already looked at some related and I found something that works
Need to cancel click/mouseup events when double-click event detected
function singleClick(e) {
// do something, "this" will be the DOM element
}
function doubleClick(e) {
// do something, "this" will be the DOM element
}
$(selector).click(function(e) {
var that = this;
setTimeout(function() {
var dblclick = parseInt($(that).data('double'), 10);
if (dblclick > 0) {
$(that).data('double', dblclick-1);
} else {
singleClick.call(that, e);
}
}, 300);
}).dblclick(function(e) {
$(this).data('double', 2);
doubleClick.call(this, e);
});
However, if I use .on("click") instead of .click(), this code doesn't work.
Any idea why this is? I have to use .on() so using .click() is not an option