Skip to content

Instantly share code, notes, and snippets.

@dscamahorn
Created August 11, 2015 16:58
Show Gist options
  • Save dscamahorn/5c98e8d6b8c55c1ce97b to your computer and use it in GitHub Desktop.
Save dscamahorn/5c98e8d6b8c55c1ce97b to your computer and use it in GitHub Desktop.
<html class="no-touch">
<head>
<style>
.no-touch h1 {
color:red;
}
.touch h1 {
color:green;
}
</style>
</head>
<body>
<h1>Hello world</h1>
<script>
//Detect touch capabilities and add class accordingly
var hasTouch = 'ontouchstart' in window;
var el = document.getElementsByTagName('html');
if (hasTouch === true) {
el.classList.add('touch');
el.classList.remove('no-touch');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment