Commit 5836b351 authored by jonathan Courat's avatar jonathan Courat

Add minus button and decrement function for the quantity

parent 8d7fc0a2
......@@ -23,7 +23,20 @@
text-decoration: none;
display: inline-block;
font-size: 18px;
margin: 4px;
margin: 2px;
cursor: pointer;
}
.minusBt {
background-color: #f44336; /* Red */
border: none;
color: white;
padding: 2px 11px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 18px;
margin: 0px;
cursor: pointer;
}
......
......@@ -17,6 +17,7 @@
<label for="cat1">Pain</label>
<p class="quantity">1</p>
<button class="plusBt">+</button>
<button class="minusBt">-</button>
</div>
<div class="itemToSelect noprint">
<input type="checkbox" id="item_2" name="cat_1" value="item 2">
......@@ -24,6 +25,7 @@
<label for="cat_1">beurre</label>
<p class="quantity">1</p>
<button class="plusBt">+</button>
<button class="minusBt">-</button>
</div>
</fieldset>
......@@ -37,6 +39,7 @@
<label for="cat_2">fromage rapé</label>
<p class="quantity">1</p>
<button class="plusBt">+</button>
<button class="minusBt">-</button>
</div>
<div class="itemToSelect noprint">
<input type="checkbox" id="item_4" name="cat_2" value="item 2">
......@@ -44,6 +47,7 @@
<label for="cat_2">Yahourt</label>
<p class="quantity">1</p>
<button class="plusBt">+</button>
<button class="minusBt">-</button>
</div>
</fieldset>
</body>
......
......@@ -40,7 +40,7 @@ addEventListenerList(items, 'click', displayItem);
//plusBt[0].previousElementSibling.innerHTML = Number(plusBt[0].previousElementSibling.innerHTML) + 1;
/* PLUS BUTTON */
let plusBt = document.querySelectorAll('.plusBt');
function incrementQuantity() {
......@@ -48,4 +48,15 @@ function incrementQuantity() {
this.previousElementSibling.innerHTML = Number(this.previousElementSibling.innerHTML) + 1;
}
addEventListenerList(plusBt, 'click', incrementQuantity);
\ No newline at end of file
addEventListenerList(plusBt, 'click', incrementQuantity);
/* MINUS BUTTON */
let minusBt = document.querySelectorAll('.minusBt');
function decrementQuantity() {
console.log(this);
this.previousElementSibling.previousElementSibling.innerHTML = Number(this.previousElementSibling.previousElementSibling.innerHTML) - 1;
}
addEventListenerList(minusBt, 'click', decrementQuantity);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment