Am I a touchdevice?

by Jens Grochtdreis

HTML

<h1 id="test">I am no touchdevice!</h1>

CSS

h1 {font-size: 30px; color: red;}
/* styling basics */
html {padding: 20px 0; background-color: #efefef;}
body {width: 80%; padding: 40px; margin: 0 auto; background: #fff; box-shadow: 1px 1px 5px rgba(0,0,0,0.5); font-family: Verdana, Arial, sans-serif; font-size: 14px;}

JavaScript

var is_touchdevice = 'ontouchstart' in document.documentElement || window.Touch || 'createTouch' in document;

if (is_touchdevice == true) {
    document.getElementById("test").innerHTML = "I am a touchdevice!";
    document.getElementById("test").style.color = "green";
}