Skip to content

Instantly share code, notes, and snippets.

@msrafi
Created September 14, 2015 20:31
Show Gist options
  • Save msrafi/6988c35ca413f138c945 to your computer and use it in GitHub Desktop.
Save msrafi/6988c35ca413f138c945 to your computer and use it in GitHub Desktop.
jquery Double Click
var DELAY = 700,
clicks = 0,
timer = null;
$(document).ready(function() {
$(document).on("click", 'td.calendarDesc', function(e){
clicks++; //count clicks
if(clicks === 1) {
timer = setTimeout(function() {
alert('Single Click'); //perform single-click action
clicks = 0; //after action performed, reset counter
}, DELAY);
} else {
clearTimeout(timer); //prevent single-click action
alert('Double Click'); //perform double-click action
clicks = 0; //after action performed, reset counter
}
})
.on("dblclick",'td.calendarDesc', function(e){
e.preventDefault(); //cancel system double-click event
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment