Skip to content

Instantly share code, notes, and snippets.

@ahmednuaman
Created November 16, 2010 15:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmednuaman/701964 to your computer and use it in GitHub Desktop.
Save ahmednuaman/701964 to your computer and use it in GitHub Desktop.
A simple little script to check for a touch enabled device
var el = document.createElement( 'div' );
el.setAttribute( 'ontouchstart', 'return;' );
if ( typeof el.ontouchstart == 'function' )
{
// yay a touch device!
}
@ahmednuaman
Copy link
Author

Updated since Mr Jobs likes making things up

@remotezygote
Copy link

Wouldn't

if(document.body.ontouchstart) { /* yay touch device */ }

work just as well (and not make you create things/initialize vars/set attributes)?

@ahmednuaman
Copy link
Author

Interesting... Must've been the sleepless nights of the project that caused me to come up with this special way!

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