How to display product details using sessionStorage in jquery?

0

I’m trying to create a jquery cart for a project I’m working on. The products are gotten from a json file. I want when I click on each product should display the product details in another page which is product.html.

Here is my code

$('#items').delegate('.items', 'click', `${item.name}`, function(name) {
        sessionStorage.setItem('itemName', name);
         window.location = 'product.html?name=${item.name}';
        return false;
      })

      function getItem(subcategory){
        let itemName = sessionStorage.getItem('itemName');
        console.log(sessionStorage.getItem('itemName'));
        subcategory.items[i].forEach(function (name) {
            console.log(name);
            let output =`
        <div class="row">
          <div class="col-md-4">
            <img src="${item.imageLink}" class="thumbnail">
          </div>
          <div class="col-md-8">
            <ul>
              <li> ${item.name}</li>
              <li> ${item.description}</li>
              <li> ${item.price}</li>
            </ul>
          </div>
        </div>
      `;

      $('#item').html(output);
        })
      }

for this line sessionStorage.setItem('itemName', name); I used name as the value because I wanted to get something unique from the items, is it the correct thing to use?

Link: How to display product details using sessionStorage in jquery?
Source: Stack Jquery

Share.

About Author

Leave A Reply