Reputation: 113
Im creating a very simple till system, and adding items seems to work very well, but when it comes to removing an item from the order, it doesnt quite work out.
Got my code loaded up here http://jsfiddle.net/Unjustified/sVX2x/
once Ive added a few options, then remove the first item, it will set the total to 0, and minus the value * the order in which I originally added them. i.e.
item 1 = £2
item 2 = £3
item 3 = £4
Total = £9
Then remove item 2 and the total should be £6 but instead is £3 (item value multiplied by position in list)
if anyone has any ideas, I would be very greatful, Thanks!
Upvotes: 0
Views: 115
Reputation: 150108
You have your click event handler for the remove logic nested in the click handler for adding. It should be separate.
Also, since you are dynamically adding and removing elements in the list of purchases, you need to use on()
(API Docs) to capture changes in the DOM.
Working fiddle:
Upvotes: 1