i have this:
<p>Qté : ${quantity}</p> <input type="number" class="itemQuantity" name="itemQuantity" min="1" max="100" value="${quantity}">being added dynamically in html for each product of a cart.
I want that input to update inside "p"tag and inside the cart when there a change inside this input.
But lets say for now that i want to update inside "p"tag and value when i change the number with arrow or type it.
value="${quantity}" --> that code is saying take the quantity for this product (in cart/localstorage) and set it to default.
i want the changed value to be the new default, if you know what i mean. And i also need this to work for all the products, for now it only works with the first item fo the cart.
for now i'm stuck with
const quantityBox = document.querySelector(".itemQuantity");
quantityBox.addEventListener("change", function () {
//update value function });
If I understood your problem correctly, I think what you want is:
I think you can use Element.previousElementSibling like this:
const quantityBox = document.querySelector(".itemQuantity");
quantityBox.addEventListener("change", function (e) {
const prevP = e.target.previousElementSibling;
prevP.innerText = "Qté : " + e.target.value;
});