HTML ontouchstart Event Attribute
Description
The ontouchstart HTML event attribute is used to specify a script that is executed whenever a user touches an HTML element. This event is only supported on touch-enabled devices, such as smartphones and tablets.
When a user touches an element with the ontouchstart event attribute, the associated script is executed. The script can be used to perform a variety of tasks, such as:
- Changing the element's appearance
- Displaying a message
- Navigating to a new page
- Playing a sound
The ontouchstart event can be used to create a variety of interactive web experiences. For example, you could use it to create a button that changes color when it is touched, or a game that requires the user to tap on objects on the screen.
The ontouchstart event is a powerful tool that can be used to create engaging and interactive web pages.
Here is an example of how to use the ontouchstart event attribute:
<button ontouchstart="myFunction()">Touch me!</button>
function myFunction() {
alert("You touched me!");
}
When the user touches the button, the myFunction() function is executed, and an alert message is displayed.
Syntax
<element ontouchstart="script">
Values
- scriptThe name of the script to use when the event has been triggered.
Example
Browser Support
The following information will show you the current browser support for the HTML ontouchstart event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.
This event attribute is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 21st October 2023
