Created
March 6, 2014 20:19
-
-
Save esteinborn/9398782 to your computer and use it in GitHub Desktop.
Detect whether its a touch or click even that should be fired. jQuery.
This file contains hidden or 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
// This checks document to see if touchstart exists | |
// if it does, then your event is 'touchstart' | |
// if it doesn't (most desktop browsers) then its 'click'. | |
var clickEventType = ((document.ontouchstart!==null)?'click':'touchstart'); | |
// Old .bind don't use | |
$('.foo').bind(clickEventType, function(e){}); | |
//Better yet, use .on() for binding: | |
$('body').on(clickEventType, '.foo', function(e){}); | |
// You can then trigger using the same event type: | |
$('.foo').trigger(clickEventType); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment