forked from Anushkabh/krishiconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwishlist.js
36 lines (24 loc) · 988 Bytes
/
wishlist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var wishlistItems = JSON.parse(localStorage.getItem('wishlistItems')) || [];
var wishlistItemsContainer = document.getElementById('wishlist-items');
function renderWishlist() {
wishlistItemsContainer.innerHTML = '';
wishlistItems.forEach(function(item) {
var itemElement = document.createElement('div');
itemElement.classList.add('wishlist-item');
var itemName = document.createElement('span');
itemName.textContent = item.name;
itemName.classList.add('item-name');
itemElement.appendChild(itemName);
var itemPrice = document.createElement('span');
itemPrice.textContent = '₹' + item.price;
itemPrice.classList.add('item-price');
itemElement.appendChild(itemPrice);
wishlistItemsContainer.appendChild(itemElement);
});
}
renderWishlist();
function emptyWishlist() {
localStorage.removeItem('wishlistItems');
wishlistItems = [];
renderWishlist();
}