Map click events to touch events in jQuery
To map click events to "touch events", I put together this based on the feedback here: http://stackoverflow.com/questions/7018919/how-to-bind-touchstart-and-click-events-but-not-respond-to-both
Update Rodney Rehm made a nicer version of this. Thanks Rodney! https://gist.github.com/rodneyrehm/6464641
$.fn.activate = function(runFunc) {
$(this).on('touchend', function(e){
$(this).addClass("touched");
runFunc();
e.preventDefault();
});
$(this).on('click', function(e){
if (!($(this).hasClass('touched'))) {
runFunc();
e.preventDefault();
e.stopPropagation();
};
});
}
Written by Rachel Nabors
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Touch
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#