Code: Select all
Code: Select all
// function to add items to shopping
let cartbutton = document.getElementsByName('ropebutton');
console.log(cartbutton) // prints node []
const cart = [];
for(var i = 0; i < cartbutton.length; i++) {
let button = cartbutton[i];
console.log(button); // doesn't print
button.addEventListener('click', (event) => {
console.clear();
console.log(event.target);
console.log(event.target.dataset.test);
cart.push(event.target.dataset.test);
console.log(cart)
});
};
Code: Select all
[img]static/111.jpg[/img]
$4,500 buy
[img]static/112.jpg[/img]
$3,500 buy
[img]static/113.jpg[/img]
$1,550 buy
```
Mobile version