Skip to content

Instantly share code, notes, and snippets.

@rogerclark
Last active December 20, 2015 15:59
Show Gist options
  • Save rogerclark/6157943 to your computer and use it in GitHub Desktop.
Save rogerclark/6157943 to your computer and use it in GitHub Desktop.
bind both click and dblclk on the same jQuery element (by simulating dblclk)
function clickAndDoubleClick(el, fnclick, fndblclk) {
var clicked = false;
var timeoutid;
// for IE7, use 'mouseup'
el.on('click', function() {
if (clicked) {
clicked = false;
clearTimeout(timeoutid);
fndblclk.apply(this, arguments);
} else {
clicked = true;
var clickthis = this;
var clickargs = arguments;
timeoutid = setTimeout(function() {
clicked = false;
fnclick.apply(clickthis, clickargs);
}, 200);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment