HTML | DOM TouchEvent
When a user touches a touch-based device the resulted events are handled by TouchEvent Object. The touch events consist of three types of interfaces i.e. Touch, TouchEvent and TouchList. The single contact point events on a touch-sensitive device are handled by the Touch interface.
The events which have a list of contact points with a touch surface, one touch point per contact are handled by TouchList interface. When an event is sent which have the state of contacts with touch-sensitive surface changes, those events are handled by TouchEvent interface.
Event Type:
- ontouchstart:When a finger is placed on a touch screen, ontouchstart event occurs.
Syntax:<p ontouchstart="TouchFunction()">Touch me</p>
Example-1:
<!DOCTYPE html><html><head><title>DOM touchstart Event</title></head><body><pontouchstart="TouchFunction()">Touch me!</p><pid="p1"></p><script>function TouchFunction() {document.getElementById("p1").innerHTML = "Hello World";}</script></body></html>chevron_rightfilter_noneOutput:
-
Before touching the screen:

- After touching the screen:

-
Before touching the screen:
- ontouchmove:When user moves finger over touch screen, ontouchmove event occurs.
Syntax:<p ontouchmove="TouchFunction()">Touch me</p>
Example-2:
<!DOCTYPE html><html><head><title>DOM touchmove Event</title></head><body><pontouchmove="TouchFunction()">Touch me!</p><pid="p1"></p><script>function TouchFunction() {var x = event.touches[0].clientX;var y = event.touches[0].clientY;document.getElementById("p1").innerHTML ="X & Y coordinate of current touch point is:"+ x + ", " + y;}</script></body></html>chevron_rightfilter_noneOutput:
-
Before moving the fingers over screen:

- After moving the fingers over screen:

-
Before moving the fingers over screen:
- ontouchend:When user removes the finger from an event over touch screen, ontouchend event occurs.
Syntax:<p ontouchend="TouchFunction()">Touch me</p>
Example-3:
<!DOCTYPE html><html><head><title>DOM touchstart Event</title></head><body><pontouchend="TouchFunction()">Touch me!</p><pid="p1"></p><script>function TouchFunction() {document.getElementById("p1").innerHTML = "Hello World";}</script></body></html>chevron_rightfilter_noneOutput:
-
Before removing the fingers from screen:

- After removing the fingers from screen:

-
Before removing the fingers from screen:
Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge
Recommended Posts:
- HTML | DOM TouchEvent altKey Property
- HTML | DOM TouchEvent ctrlKey Property
- HTML | DOM TouchEvent shiftKey Property
- HTML | DOM TouchEvent touches Property
- HTML | DOM TouchEvent targetTouches Property
- HTML | DOM TouchEvent metaKey Property
- HTML Course | Structure of an HTML Document
- HTML Course | Basics of HTML
- HTML | DOM HTML Object
- HTML | <hr> Tag
- HTML | <q> Tag
- HTML | <ul> Tag
- HTML | b Tag
- HTML | bdo Tag
- HTML | <nav> Tag
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



