Skip to content

Instantly share code, notes, and snippets.

@AndrewBarba
Last active October 25, 2020 17:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewBarba/5477454 to your computer and use it in GitHub Desktop.
Save AndrewBarba/5477454 to your computer and use it in GitHub Desktop.
/*** ANDREW BARBA ***/
/**** April 2013 ****/
/********************/
// A replacement for jQuery's .click() event that
// automatically supports taps on mobile devices
// and clicks on desktops
jQuery.fn.touchClick = function(fnc)
{
if (fnc) {
this.bind("touchend click",function(event){
event.stopPropagation();
event.preventDefault();
if(event.handled !== true) {
event.handled = true;
return fnc.call(this,event);
} else {
return false;
}
});
} else {
this.trigger("click");
}
}
/**
Sample usage:
$("div#button").touchClick(function(){
alert("You tapped/clicked the button");
});
**/
@sandeepjain2015
Copy link

@AndrewBarba thanks it's working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment