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

191
Visualizações
Event Listener for button to run javascript for next few seconds

I've got a bit of javascript that hides a button if a set of criteria aren't yet met. (it hides the "NEXT" button if the customer hasn't added all required services to their basket)

I need the javascript to fire every time the customer reaches the basket and understand this can be done via an event listener.

To reach the basket the customer will always click a button which has a classname of "bookly-hour"

Is it possible to make the javascript fire a few seconds after the click of the "bookly-hour" button?

Edit / Update

Q:

"Can you show us the code that you got for now Do you have all the code that the button should trigger, but not the button click event handler?" ...

A:

That's right I have the code the button needs to trigger. I need help with triggering it when the button is clicked. The code:

const sessions = ['session 1', 'session 2', 'session 3'];

const searchTarget = document.querySelector('.bookly-cart-step');
const submitButton = document.querySelector('.bookly-next-step');

if (searchTarget.textContent.includes('session')) {
  if (
    !sessions.every(session =>
      searchTarget.textContent.includes(session)
    )
  ) {
    submitButton.setAttribute('disabled', '');
  } else {
    submitButton.removeAttribute('disabled');
  }
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use the window.setTimeout function, inside of your onClick handler

EDIT:

To add the click event handler you could do

submitButton.addEventListener('click', yourHandler);

Where yourHandler is the function you want to trigger
If you want the code inside of yourHandler to fire few seconds later you could do

submitButton.addEventListener('click', () => window.setTimeout(yourHandler, 5000)); // 5s later

(or put the setTimeout inside the handler function)

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