ontouchstart
ontouchstart event
The ontouchstart
event handler runs a script when a touch point is placed on the touch surface. It is commonly used to initiate touch interactions and gestures on mobile devices.
Syntax
In HTML
<element ontouchstart="myScript">
In JS
object.ontouchstart = myScript;
addEventListener()
function is used. In JavaScript, the
object.addEventListener("touchstart", myScript);
Example
<!DOCTYPE html>
<html>
<body>
<h1>DOM touchstart Event</h1>
<p ontouchstart="myFunction()">Touch this paragraph to trigger a function that will write "Hello World".</p>
<p><strong>Note:</strong> This example is for touch devices only.</p>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
</body>
</html>
Values
Conclusion
The ontouchstart
event in HTML is triggered when a touch point is placed on the touch surface, initiating the touch interaction. It is commonly used for starting gestures or interactions on mobile devices, such as tapping or swiping. This event can be leveraged to create responsive interfaces, enabling interactive features right when the user touches the screen.
ontouchmove
The ontouchmove event in HTML is triggered when a touch point moves across the touch surface, enabling scripts to respond to the movement of the touch.
Window
HTML window event attributes manage user interactions and changes in the browser window, such as resizing, scrolling, and focus events.