forked from M3-Academy/practice-time-shopping-list
Adiciona função as botões de + e -.
This commit is contained in:
parent
1ff2f009c8
commit
20ce5a330f
25
app.js
Normal file
25
app.js
Normal file
@ -0,0 +1,25 @@
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const quantityInput = document.querySelector(".shopping-form-quantity-input");
|
||||
const incrementButton = document.querySelector(".shopping-form-increment-button");
|
||||
const decrementButton = document.querySelector(".shopping-form-decrement-button");
|
||||
|
||||
incrementButton.addEventListener("click", incrementQuantity);
|
||||
decrementButton.addEventListener("click", decrementQuantity);
|
||||
|
||||
function incrementQuantity() {
|
||||
const currentValue = Number(quantityInput.value);
|
||||
const newValue = currentValue + 1;
|
||||
|
||||
quantityInput.value = newValue;
|
||||
}
|
||||
|
||||
function decrementQuantity() {
|
||||
const currentValue = Number(quantityInput.value);
|
||||
const newValue = currentValue - 1;
|
||||
|
||||
if (newValue > 0) {
|
||||
quantityInput.value = newValue;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
@ -38,5 +38,7 @@
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user