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

161
Views
Number of items removed from array in each iteration of the loop increases

I need help with my simple application. When I click on the selected (highlighted) row the alert box shows and I can confirm that I'd like to remove the selected one and that's fine - the selected row is being removed. The problem is that I checked what'll happen when I select one row and close the alert box, then 2nd row and close the alert box, then 3rd one, and so on. When I finally decide to use confirm button, not only the highlighted row is being removed but also the 2nd/3rd/4th clicked row which I decided not to remove. I want my app to remove only one, selected row regardless of how many times before using confirm button I clicked in any row and closed the alert box.

Below I'm putting the code responsible for the whole thing that I'm writing about.

Thanks in advance for any comments

const alertBox = document.querySelector('.alert-box');

tableBody.addEventListener('click',(e) => {

 document.querySelector('.ok').addEventListener('click',() => {
  
  const target = e.target.parentNode.childNodes[0].textContent;
  alertBox.classList.add('no-show');

  sizesList.forEach((element,index) => {

   if (element.size.toLowerCase() === target.toLowerCase()) {

    sizesList.splice(index,1);
    localStorage.setItem('size',JSON.stringify(sizesList));
    e.target.parentNode.remove();

   };

  });

 });

 document.querySelector('.fa-times').addEventListener('click',() => alertBox.classList.add('no-show'));
});

removing row

about 4 years ago · Juan Pablo Isaza
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!