I have a shopping cart that is based on javascript. There are multiple cartrows with each the same plus and minus button. I've got these 2 simple function which adds 1 or reduces it by 1, depends on the button that is clicked.
function plus() {
var spanclass = document.getElementById('hoeveel')
var count = spanclass.innerHTML;
count++;
document.getElementById('hoeveel').innerHTML = count;
}
function minus() {
var spanclass = document.getElementById('hoeveel')
var count = spanclass.innerHTML;
if (count > 1) {
count--;
document.getElementById('hoeveel').innerHTML = count;
}
}
This works, but not when there is more than 1 item in the cart. When the plus button gets clicked on the second item in the cart the quantity of the first item gets changed.
My question here is, is it possible to only change the span class that is in the same "cartrow" class the button was clicked in?
eventListener', especially the parameters. Create a generic 'listener' and query theevent:targetfrom the passedeventparameter. E.g. MDN: Event.target