-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.html
More file actions
58 lines (50 loc) · 1.27 KB
/
cart.html
File metadata and controls
58 lines (50 loc) · 1.27 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Cart</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<h2>SPORTSMART</h2>
<nav>
<a href="home.html">Home</a>
<a href="wishlist.html">Wishlist</a>
<a href="cart.html">Cart</a>
</nav>
</header>
<div class="container">
<h3 class="page-title">🛒 My Cart</h3>
<div class="product-grid" id="cartGrid"></div>
<p class="empty" id="emptyCart"></p>
</div>
<footer>© 2025 SportsMart</footer>
<script>
const cart = JSON.parse(localStorage.getItem("cart")) || [];
const grid = document.getElementById("cartGrid");
const empty = document.getElementById("emptyCart");
if(cart.length === 0){
empty.innerText = "Your cart is empty 😢";
}
cart.forEach((p,index)=>{
grid.innerHTML += `
<div class="card">
<img src="${p.img}">
<div class="card-body">
<h4>${p.name}</h4>
<p class="price">₹${p.price}</p>
<button class="remove-btn" onclick="removeItem(${index})">Remove</button>
</div>
</div>
`;
});
function removeItem(i){
cart.splice(i,1);
localStorage.setItem("cart",JSON.stringify(cart));
location.reload();
}
</script>
</body>
</html>