Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
Store cart and delete items in static website

I am using Vanilla javascript to manipulate items in Cart . Whenever i want to delete an item i want to store it when I refresh the page , I didn't succeed using localStorage in this case :

function Cart()
{
for(let i = 0 ; i <addCart.length; i++ )
{
    addCart[i].addEventListener('click', (event)=>
    {
       const Target = event.target
       const titleTarget = Target.parentElement.parentElement.getElementsByTagName("h3")[0].innerText
       const priceTarget = Target.parentElement.parentElement.getElementsByTagName("span")[0].innerText
       const imageTarget = Target.parentElement.parentElement.getElementsByTagName("img")[0].src
        addToCart(titleTarget,priceTarget,imageTarget)
       console.log(titleTarget,priceTarget,imageTarget)
       addCart[i].parentElement.remove()

    })
}
    function addToCart(titleTarget,priceTarget,imageTarget)
    {
        var cartRow = document.createElement('div')
        cartRow.classList.add('grid-cart')
        var cartRowContent = `
                <img class="cart-image" src="${imageTarget}" alt="cart image" />
            <div class="grid-title">
                <h3 class="cart-title">${titleTarget}</h3>
                <h4 class="cart-title-size">Size 11</h4>
            </div>
                <h3 class="cart-price">${priceTarget}</h3>
        `
        cartRow.innerHTML = cartRowContent
        dropCart[0].append(cartRow)
    }
   
}
localStorage.setItem('cartsetting',Cart())
localStorage.getItem('cartsetting')

So this code describes , that I will click add to cart and it will be removed from the main page . And will be added in the cart , but everything get reset after I refresh ! any solution ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!