I was trying to build a shopping cart with Vanilla javascript and HTML &CSS. I have run into a problem where by I could not remove an item form the shopping cart. I have been using the Local storage. When I click on the remove icon I get this error:
myown.js:171 Uncaught TypeError: Cannot read property 'getElementsByClassName' of undefined at HTMLElement.
I have tried many things but it seems hard to get around. Any help will be appreciated.
My code:
function deleteButtons(){
let deleteButtons =document.querySelectorAll('.product ion-icon ');
console.log("deleteButtons ");
let productName;
for (i=0; i< deleteButtons.length; i++) {
deleteButtons[i].addEventListener('click', () =>{
console.log("clicked");
// productName = deleteButtons[i].parentElement;
productName = deleteButtons[i].parentElement.textContent;
console.log(productName );
});
}
}