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

124
Visualizações
How to detect whether 2 buttons are clicked one after the another in javascript?

I've to trigger an alert when button #1 is clicked and then after the button 2# is clicked

if button 1# is clicked and immediately user is clicked on another button button x# then alert should not be trigger.

I've to track those 2 clicks that are one after the other so that i'll embed the js script in the google tag manager

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This example will trigger an alert when Button 3 is clicked after Button 1.

var Last;
function getLast(t){
  if(Last=='btn1'&&t.id=='btn3')alert('btn1 then btn3')
  Last=t.id;
};
<button id='btn1' onclick='getLast(this);'>Button 1</button>
<button id='btn2' onclick='getLast(this);'>Button 2</button>
<button id='btn3' onclick='getLast(this);'>Button 3</button>

EDIT: with a timeout (like sugsested on comments), sequence must be done before 2 sec.

var Last,time;
function getLast(t){
  if(Last=='btn1'&&t.id=='btn3')alert('btn1 then btn3');
  Last=t.id;
  clearTimeout(time);
  time=setTimeout(function(){Last='';}, 2000);
};
<button id='btn1' onclick='getLast(this);'>Button 1</button>
<button id='btn2' onclick='getLast(this);'>Button 2</button>
<button id='btn3' onclick='getLast(this);'>Button 3</button>

about 4 years ago · Juan Pablo Isaza Relatório
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