Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
How to prevent touchstart event while triggering click event

I just want click event handler to get executed and not the touchstart event handler (on mobile/touch devices), how can i prevent touchstart event handler from getting executed?

const container = document.getElementById("slider");
const btn = document.getElementById("btn");

container.addEventListener("touchstart", () => console.log("touchstart"));

btn.addEventListener("click", () => console.log("click"));
#slider {
    width: 400px;
    height: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: aquamarine;
    margin: 100px auto;
    border-radius: 10px;
}

#btn {
    width: 40px;
    height: 40px;
    text-align: center;
    line-height: 40px;
    background-color: lightcoral;
    padding: 30px;
    border-radius: 10px;
    cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="slider">
        <div id="btn">btn</div>
    </div>
</body>
</html>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!