-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducts.html
More file actions
198 lines (193 loc) · 10 KB
/
products.html
File metadata and controls
198 lines (193 loc) · 10 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<div class='header-content'>
<img src="images/logo.png" alt="logo" width="221px">
<h1>Gund-arm Co</h1>
</header>
<div class="nav">
<nav>
<a href="index.html">Home</a>
<a href="products.html">Products</a>
<a href="contact.html">Contact Us</a>
<a href="login.html">Login</a>
</nav>
</div>
<main>
<section class="product-list">
<h2 class="section01-title">Product</h2>
<div class="product-container">
<div class="product">
<img src="images/p1.png" alt="1/144 HG Gundam Aerial" width="350">
<div class="item-desc">
<div class="item-name">
<h4>1/144 HG Gundam Aerial</h4>
<div class="item-price">
<h5>$32</h5>
</div>
<button type="button">Add to Cart</button>
</div>
</div>
</div>
<div class="product">
<img src="images/p2.jpg" alt='HG 1/144 Gundam Aerial "Permet Score 6"' width="350">
<div class="item-desc">
<div class="item-name">
<h4>HG 1/144 Gundam Aerial "Permet Score 6"</h4>
<div class="item-price">
<h5>$60</h5>
</div>
<button type="button">Add to Cart</button>
</div>
</div>
</div>
</div>
<div class="product-container">
<div class="product">
<img src="images/p4.jpg" alt="HG 1/144 Alie Strike Gundam" width="350">
<div class="item-desc">
<div class="item-name">
<h4>HG MIRASOUL FLIGHT UNIT 1/144</h4>
<div class="item-price">
<h5>$40</h5>
</div>
<button type="button">Add to Cart</button>
</div>
</div>
</div>
<div class="product">
<img src="images/p3.jpg" alt="HG 1/144 Gundam Aerial Rebuild" width="350">
<div class="item-desc">
<div class="item-name">
<h4>HG 1/144 Gundam Aerial Rebuild</h4>
<div class="item-price">
<h5>$40</h5>
</div>
<button type="button">Add to Cart</button>
</div>
</div>
</div>
</div>
<div class="product-container">
<div class="product">
<img src="images/p5.jpg" alt="HG 1/144 RX78-2 Gundam (Revive)" width="350">
<div class="item-desc">
<div class="item-name">
<h4>HG 1/144 RX78-2 Gundam (Revive)</h4>
<div class="item-price">
<h5>$40</h5>
</div>
<button type="button">Add to Cart</button>
</div>
</div>
</div>
<div class="product">
<img src="images/p6.jpg" alt="HG 1/144 Perfect Strike Freedom Gundam" width="350">
<div class="item-desc">
<div class="item-name">
<h4>HG 1/144 Perfect Strike Freedom Gundam</h4>
<div class="item-price">
<h5>$50</h5>
</div>
<button type="button">Add to Cart</button>
</div>
</div>
</div>
</div>
<div class="product-container">
<div class="product">
<img src="images/p7.jpg" alt="HG 1/144 Nu Gundam" width="350">
<div class="item-desc">
<div class="item-name">
<h4>HG 1/144 Nu Gundam</h4>
<div class="item-price">
<h5>$40</h5>
</div>
<button type="button">Add to Cart</button>
</div>
</div>
</div>
<div class="product">
<img src="images/p8.jpg" alt="HG 1/144 Strike Freedom" width="350">
<div class="item-desc">
<div class="item-name">
<h4>HG 1/144 Strike Freedom</h4>
<div class="item-price">
<h5>$40</h5>
</div>
<button type="button">Add to Cart</button>
</div>
</div>
</div>
</div>
</section>
<section class= "Shopping Cart" id = "cart">
<h2 class="section02-title">Shopping Cart</h2>
</section>
</main>
<footer>
<p>©2024 Hyunmyung Park and Hongwoo Yoon</p>
</footer>
<script>
document.addEventListener('DOMContentLoaded', (event) =>
{
document.querySelectorAll('.product .item-name button').forEach(button =>
{
button.addEventListener('click', function()
{
const productDiv = this.closest('.product');
const productName = productDiv.querySelector('.item-name h4').innerText;
const productPrice = productDiv.querySelector('.item-price h5').innerText;
addToCart(productName, productPrice);
});
});
});
function addToCart(name, price) {
let cart = document.getElementById('cart');
let existingItem = [...cart.querySelectorAll('.cart-item')].find(item => item.dataset.name === name);
if (existingItem)
{
let quantity = existingItem.querySelector('.quantity');
quantity.innerText = parseInt(quantity.innerText) + 1;
}
else
{
let item = document.createElement('div');
item.classList.add('cart-item');
item.dataset.name = name;
item.innerHTML = `
<div class="cart-item">
<div class="cart-detail name">${name}</div>
<div class="cart-detail price">${price}</div>
<div class="cart-detail quantity-container">
<p class="quantity">1</p>
<button class="remove-btn">Remove</button>
</div>
</div>
`;
cart.appendChild(item);
item.querySelector('.remove-btn').addEventListener('click', function()
{
let quantity = item.querySelector('.quantity');
let newQuantity = parseInt(quantity.innerText) - 1;
if (newQuantity > 0)
{
quantity.innerText = newQuantity;
alert(`1 ${name} removed from cart`);
}
else
{
cart.removeChild(item);
alert(`${name} removed from cart`);
}
});
}
alert(`${name} added to cart`);
}
</script>
</body>
</html>