Timer Delay after clicking button

I have a button with next-step in my funnelish page. When clicked, it opens a “loading” pop up. To give the loading effect, I want there to be a delay between when the button is pressed and when it actually changes URL and goes to the next step. I tried many different versions of the code but none work.

await delay (3000)
setTimeout

do not work, please help

you can delay after clicking the button here is the steps.

  1. Add an id attribute with the value "buy-now" to the “Buy Now” button.

  2. Create a popup that displays a loading effect. Below the loading effect, add a button with the id next-step-btn, and make the button initially invisible. After the loading effect is complete, reveal the button and set it to proceed to the next step.


  1. add this javascript code:
const btn = document.querySelector("#next-step-btn");
const buynow = document.querySelector("#buy-now");

buynow.addEventListener("click",()=> {
    console.log("click");
    // This function will be executed after 2000 milliseconds (5 seconds)
setTimeout(function() {
    btn.click();
}, 5000); // you can set the delay time from here 5000

})

1 Like