MDN self-hosted library · e01.org

TouchEvent: touches property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
someElement.addEventListener("touchstart", (e) => {
  // Invoke the appropriate handler depending on the
  // number of touch points.
  switch (e.touches.length) {
    case 1:
      handle_one_touch(e);
      break;
    case 2:
      handle_two_touches(e);
      break;
    case 3:
      handle_three_touches(e);
      break;
    default:
      console.log("Not supported");
      break;
  }
});