Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda