Skip to content

Instantly share code, notes, and snippets.

@deskid
Forked from pangui/prevent_double_click.js
Created August 28, 2017 06:05
Show Gist options
  • Save deskid/c76d896f759f88b2c15e2556f48818de to your computer and use it in GitHub Desktop.
Save deskid/c76d896f759f88b2c15e2556f48818de to your computer and use it in GitHub Desktop.
Prevent double click!
// jQuery plugin to prevent double click
jQuery.fn.preventDoubleClick = function() {
$(this).on('click', function(e){
var $el = $(this);
if($el.data('clicked')){
// Previously clicked, stop actions
e.preventDefault();
e.stopPropagation();
}else{
// Mark to ignore next click
$el.data('clicked', true);
// Unmark after 1 second
window.setTimeout(function(){
$el.removeData('clicked');
}, 1000)
}
});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment