जब कोई उपयोगकर्ता टचस्क्रीन डिवाइस से इंटरैक्ट करता है तो जावास्क्रिप्ट में टच इवेंट सक्रिय हो जाते हैं।
निम्नलिखित सूचक घटना गुण हैं
<टेबल><थेड>जावास्क्रिप्ट में स्पर्श घटनाओं के लिए कोड निम्नलिखित है -
उदाहरण
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.result,
.sample {
font-size: 18px;
color: blueviolet;
font-weight: 500;
}
.sample {
color: red;
}
</style>
</head>
<body>
<h1>Touch events in JavaScript</h1>
<div class="sample">Here is some sample text to touch</div>
<div class="result"></div>
<h3>Touch on the above paragraph to make output in the below paragraph visible</h3>
<script>
let resEle = document.querySelector(".result");
let sampleEle = document.querySelector(".sample");
sampleEle.addEventListener("touchstart", () => {
resEle.innerHTML = "Touch start event has been triggered";
});
</script>
</body>
</html> उपरोक्त कोड निम्न आउटपुट उत्पन्न करेगा -
आउटपुट

पैराग्राफ को छूने पर -
