
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Explain touch events in JavaScript
The touch events in JavaScript are fired when a user interacts with a touchscreen device.
Following are the pointer event properties
Event | Description |
---|---|
touchstart. | It is fired when the touch point is placed on the touch surface. |
touchmove | It is fired when the touch point is moved along the touch surface. |
touchend | It is fired when the touch point is removed from the touch surface. |
touchcancel | It is fired when the touch point has been disrupted |
Following is the code for touch events in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; color: blueviolet; font-weight: 500; } .sample { color: red; } </style> </head> <body> <h1>Touch events in JavaScript</h1> <div class="sample">Here is some sample text to touch</div> <div class="result"></div> <h3>Touch on the above paragraph to make output in the below paragraph visible</h3> <script> let resEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); sampleEle.addEventListener("touchstart", () => { resEle.innerHTML = "Touch start event has been triggered"; }); </script> </body> </html>
The above code will produce the following output −
Output
On touching the paragraph −
- Related Articles
- Explain Key-events in JavaScript?
- Explain Scroll events in JavaScript.
- Explain load events in JavaScript?
- Explain focus events in JavaScript.
- How to use jQuery touch events plugin for mobiles?
- Controlling Whether Mouse & Touch Allowed with CSS pointer-events Property
- Explain Built-in Events in Backbone.js
- What are events in JavaScript?
- Explain comprehensive timeline events in mergers and acquisition
- How to register events in JavaScript?
- What are custom events in JavaScript?
- What are JavaScript DOM Events?
- How to Handle JavaScript Events in HTML?
- What is cross-browser window resize events in JavaScript?
- Difference between document load and DOMContentLoaded events in JavaScript

Advertisements