Created
May 28, 2013 23:06
-
-
Save raddevon/5666828 to your computer and use it in GitHub Desktop.
jQuery function to bind both touch and click events simultaneously
From http://jsbin.com/ijizat/25/
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
function touchClick(sel, fnc) { | |
$(sel).live('touchstart click', function(event){ | |
event.stopPropagation(); | |
event.preventDefault(); | |
if(event.handled !== true) { | |
fnc(event); | |
event.handled = true; | |
} else { | |
return false; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original version of this function from jsbin had both
Touch
andClick
capitalized in the definition. This caused JSLint to interpret it as a prototype rather than a function and give a warning because I had not usednew
to instantiate the new object. I changed the case to fix the problem.