N
N
Nikita HQ2020-04-15 15:46:23
JavaScript
Nikita HQ, 2020-04-15 15:46:23

Why doesn't blocking the button after it is pressed, JS?

Hello! It turns out the situation is, I need to remove the button after it is pressed, I did this .
Everything works great, but I can't figure out why the same code doesn't work on my site .

5e9701e8a1f23969339367.png

Although the html code of the button is completely identical, can anyone tell me, I have been suffering with this issue for a very long time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav, 2020-04-15
@abalduy

and maybe there are more blocks with the class "simplecheckout-button-right" on the site,
it seems to me that in your js block you need a closure:

const simplecheckoutButtonRight = document.querySelectorAll(".simplecheckout-button-right");

simplecheckoutButtonRight.forEach(el => {
  const btn = el.querySelector(".button");
  ((b)=>{
    b.addEventListener("click", function() {
      this.remove();
    });
  })(btn)
});

try this,
maybe i'm wrong

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question