ontouchend

The ontouchend event in HTML is triggered when a touch point is lifted from the touch surface, allowing scripts to respond to the completion of the gesture.

ontouchend event

The ontouchend event handler activates a script when a touch point is lifted from the touch surface. It is commonly used to manage the conclusion of touch interactions on mobile devices.

Syntax

In HTML

index.html
<element ontouchend="myScript">

In JS

script.js
object.ontouchend = myScript;

In JavaScript, the addEventListener() function is used.

script.js
object.addEventListener("touchend", myScript);

Example

::event-ontouchend ::
index.html
<!DOCTYPE html>
<html>
<body>
<h1>DOM touchend Event</h1>
<p ontouchend="myFunction()">Touch this paragraph, then release the touch 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 ontouchend event in HTML is triggered when a touch point is removed from the touch surface, signaling the end of a touch interaction. It's especially useful for responding to gestures such as taps, drag-and-drop actions, or swipes on touch-enabled devices. Developers can use this event to perform actions once a touch gesture is completed, enhancing user interaction.