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

189
Views
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 answers
Answer question

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 Report
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!