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..

16th Jul 2020, 9:24 PM
Prosper Emebo
Prosper Emebo - avatar
7 Respuestas
+ 10
Where's your code??
16th Jul 2020, 9:30 PM
Shruti
Shruti - avatar
+ 2
Of course, no one can tell what you are doing wrong without seeing your code.
16th Jul 2020, 9:26 PM
Ore
Ore - avatar
+ 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()
16th Jul 2020, 9:50 PM
Ore
Ore - avatar
+ 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?
16th Jul 2020, 10:21 PM
Ore
Ore - avatar
+ 1
@ore Thanks alot for your help, really learnt alot :)
17th Jul 2020, 11:37 PM
Prosper Emebo
Prosper Emebo - avatar
16th Jul 2020, 9:32 PM
Prosper Emebo
Prosper Emebo - avatar
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
16th Jul 2020, 10:03 PM
Prosper Emebo
Prosper Emebo - avatar