-2
So in the following part of my code I have a function to increase the amount or decrease of each product of the store(I will leave a photo to explain better), when I press the "+" button it increases the amount and in the "-" decreases, however it only increases in the first element that has the class that I selected even I trying to increase the amount of the last product that appears, for example, if I increase the amount of the product "chocolate blend drops" it increases the amount only of the first product "milk cover". I think because I use querySelector it takes the first selected element, however I want it to select the Current element to which I click.
Quantity code:
<div>
<div class="produto_qnt_princ" data-app="product.quantity">
<input class="qnt_menor_maior" type="button" id="plus" value='-' onclick="process_geral(-1)" />
<input class="quanti qnt_menor_maior" name="quanti" class="text" size="1" type="text" value="1" maxlength="5" />
<input class="qnt_menor_maior" type="button" id="minus" value='+' onclick="process_geral(1)" />
</div>
</div>
Code of the function that is called:
function process_geral(quant){
var classValue = parseInt(document.querySelector('.quanti').value);
classValue+=quant;
//console.log(classValue);
if(classValue < 1){
document.querySelector("input.quanti").value = 1;
}else{
document.querySelector("input.quanti").value = classValue;
}
}
then the following information appears on the console: "Uncaught Typeerror: Cannot read Property 'querySelector' of Undefined"
– Arthur Davi Borba Duarte
On which line of the code?
– Isaac Bruno
in that part "var classValue = parseint(element.parentElement.querySelector('. quanti'). value);"
– Arthur Davi Borba Duarte