Javascript DOM touchstart Event

Introduction

Execute a JavaScript when the user touches a P element.

This example is for touch devices only.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p ontouchstart="myFunction()">
Touch this paragraph to trigger a function that will write "Hello World".</p>
<p id="demo"></p>

<script>
function myFunction() {//ww w .  ja  v  a2  s.c  o  m
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>

</body>
</html>

The touchstart event occurs when the user touches an element.

The touchstart event will only work on devices with a touch screen.

Bubbles: Yes
Cancelable: Yes
Event type: TouchEvent
Supported HTML tags: All HTML elements



PreviousNext

Related