Call a function when the user touches a P element (for touch screens only):
<p ontouchstart="myFunction(event)">Touch me!</p>
Try it Yourself »
The touchstart
event occurs when a user touches an element.
The touchstart
event only works on touch screens.
Event | Occurs When |
---|---|
touchstart | The user touches an element |
touchmove | The user moves the finger across the screen |
touchend | The user removes the finger from an element |
touchcancel | The touch is interrupted |
Events that are triggered from the user interface belongs to the UiEvent Object.
Property | Description |
---|---|
detail | A number with details about the event |
view | A reference to the Window object where the event occurred |
In JavaScript, using the addEventListener() method:
object.addEventListener("touchstart",
myScript);
Try it Yourself »
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | TouchEvent |
HTML tags: | All HTML elements |
ontouchstart
is a DOM Level 4 (2015) feature.
It is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
ontouchstart
is not supported in Internet Explorer 11 (or earlier).
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!