JSFiddle - React, Tailwind, and code Playground

by Justin Breen

HTML

<div>Test</div>

JavaScript

document.getElementById("div").addEventListener("touchstart", touchHandler, false);
document.getElementById("div").addEventListener("touchmove", touchHandler, false);
document.getElementById("div").addEventListener("touchend", touchHandler, false);

function touchHandler(e) {
  if (e.type == "touchstart") {
    alert("You touched the screen");
  } else if (e.type == "touchmove") {
    alert("You moved your finger!");
  } else if (e.type == "touchend" || e.type == "touchcancel") {
    alert("You removed your finger from the screen!");
  }
}

// jQuery
// $(function(){
//   $("#div").bind("touchstart", function (event) {
//     alert(event.touches.length);
//   });
// });