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

87
Views
Multiple plus and minus buttons need to use the same function

I have 3 plus and minus buttons on my page. I need all of them to do the same thing once clicked.

html:

  <div class="product1">
        <div class="product1-lable"></div>
        <div class="product1-price"></div>
        <button class="minus">+</button>
        <input class="amount" type="amount" value="0"></input>
        <button class="plus">-</button>
        </div> 

JavaScript:

            let btnAdd = document.querySelector('.plus');
            let btnSubtract = document.querySelector('.minus');
            let input = document.querySelector('input');
            btnAdd.addEventListener('click', () =>{
            input.value = parseInt(input.value) + 1;
            });
            btnSubtract.addEventListener('click', () =>{
            input.value = parseInt(input.value) - 1;
            }); 

Only the first button is working, the other 2 are not.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Working fine !

let btnAdd = document.querySelector('.plus');
let btnSubtract = document.querySelector('.minus');
let input = document.querySelector('input');
btnAdd.addEventListener('click', () => {
  input.value = parseInt(input.value) + 1;
});
btnSubtract.addEventListener('click', () => {
  input.value = parseInt(input.value) - 1;
});
<div class="product1">
  <div class="product1-lable"></div>
  <div class="product1-price"></div>
  <button class="plus">+</button>
  <input class="amount" type="amount" value="0">
  <button class="minus">-</button>
</div>

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!