Last active
October 25, 2020 17:07
-
-
Save AndrewBarba/5477454 to your computer and use it in GitHub Desktop.
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
/*** 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"); | |
}); | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AndrewBarba thanks it's working