• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

147
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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error