Untitled
Anonymous
plain_text
01/30/2025 11:54 AM
800 B
13
Indexable
const button = document.querySelectorAll('.add');
const btn = document.querySelectorAll('.remove');
const counter = document.getElementById('counter');
let count = 0;
button.forEach(button => {
button.addEventListener('click',function(){
count += 1;
counter.textContent = count;
alert('Item added to cart');
});
});
btn.forEach(btn =>{
btn.addEventListener('click', function(){
if(count>0){
count -=1;
counter.textContent = count;
}else{
alert('your cart is empty');
}
alert('Item is remove from cart');
});
});
Editor is loading...
Leave a Comment