In JavaScript, using the addEventListener()
method:
object.addEventListener("touchstart",
myScript);
This example is for touch devices only.
<!DOCTYPE html> <html> <body> <p id="myP"> Touch this paragraph to trigger a function that will write "Hello World".</p> <p id="demo"></p> <script> document.getElementById("myP").addEventListener("touchstart", myFunction); function myFunction() {/*from w w w. ja va 2s.com*/ document.getElementById("demo").innerHTML = "Hello World"; } </script> </body> </html>
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | TouchEvent |
Supported HTML tags: | All HTML elements |