score:2

Accepted answer
addToShoppingCard(e, service) {
  e.preventDefault();
  let oldItems = JSON.parse(sessionStorage.getItem('basket')) || [];
  let parent = e.target.parentNode;
  parent.classList.add('added');
  let child = parent.childNodes;
  child[0].classList.toggle('hideChoose');
  if (child[0].classList.contains('hideChoose')) {
    let index = oldItems.findIndex(s => s.id === service.id);
    console.log(oldItems);
    console.log(service);
    console.log(index);
  } else {
    oldItems.push(service);
    sessionStorage.setItem('basket', JSON.stringify(oldItems));
  }
}

Related Query

More Query from same tag