0
Loops and Iteration
i am trying to loop over items in a cart then check if target matches what i want using query selector all looping through it and then check for match, that part is working fine but it's looping more than once, please can someone help me out i'm stuck..
7 Answers
+ 10
Where's your code??
+ 2
Of course, no one can tell what you are doing wrong without seeing your code.
+ 1
Your code is so reliant on your HTML it is hard to debug. I am guessing that this bug is as a result of event bubbling in the event handler inside the for loop.
Try adding the following line of code before the if statement on line 24
event.stopPropagation()
+ 1
Emebo Prosper According to your code that is the expected behaviour. Does not sound strange to me.
If you want to delete from the specific index. Do this
https://code.sololearn.com/WaQ4p4bTXzrN/?ref=app
But I am still not sure what type of value is stored in cartContainer?
+ 1
@ore Thanks alot for your help, really learnt alot :)
0
It still doing the same thing,
What really happening is after the user have to add a product to the cart.
that why i added a loop to loop over the products and then listen form the click on the close button. Then it will remove the element. But it removing it based on the position of the loop. *position 2 -- removes 2 times. Please how can i fix that