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

163
Views
How to make my button clickable only once?

I have a button. I need to make it clickable only once. But it does not have onclick attribute. And I cannot change HTML. This has to be done only with JS. How do I do it?

<button type="submit" name="add-to-cart" value="41" class="single_add_to_cart_button button alt">
  BUY NOW
</button>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can attach a click handler to the button and set its disabled property to true:

const button = document.querySelector('button[name="add-to-cart"]');

button.addEventListener('click', function () {
  button.disabled = true;
});
<button type="submit" name="add-to-cart" value="41" class="single_add_to_cart_button button alt">BUY NOW</button>

If you ever need to re-enable the button, that would be additional logic of course. But it looks like this button is intended to submit a form which will change the page context anyway.

about 4 years ago · Juan Pablo Isaza Report

0

You can an event listener ('click') and change add the attribute. After that, remove the event listener.

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!