Created
September 14, 2015 20:31
-
-
Save msrafi/6988c35ca413f138c945 to your computer and use it in GitHub Desktop.
jquery Double Click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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