1
I have two buttons that are created according to what comes from the api:
<div class="col-2">
<button type="button" class="btn btn-success button-ok botOk" value="${element.NUMOS}" id="${element.COD_PROD}" onClick="sim(this);">SIM</button>
</div>
<div class="col-2">
<button type="button" class="btn btn-danger button-ok" value="${element.NUMOS}" id="${element.COD_PROD}" onClick="cance(this);">NÃO</button>
</div>
<div class="col">
<p class="prod">${element.PRODUTO}</p>
</div>
COD_PROD are the same in the YES and NO buttons.
The end user has to click yes or no, and as I get the data from the api, this ${element.PRODUTO}
can came more than 1, so I did with a foreach for it to create another div with the buttons and product name automatically.
Only when I click yes on a product, and I will click yes on the other, the button disables the previous clicked and only the current one is clicked.
Can someone help me?
Code that changes status:
$('button').click(function () {
var clicado = $(this); //captura o botao clicado
$('button').removeClass('ativo') // remove a classe dos demais botoes
clicado.addClass('ativo');// adiciona a classe ao botao alvo
})
could post your code that changes the status of buttons?
– Alvaro Alves
@Alvaroalves ready, I asked the question
– Maria
"Only when I click yes on one product, and I will click yes on the other, the button deactivates the previous clicked and only the current one is clicked."... your problem is on this line:
$('button').removeClass('ativo') // remove a classe dos demais botoes
– Alvaro Alves
Yeah, but I’ve tried a lot of other ways and I can’t fix that
– Maria
let’s see if I understand: 1 - You click ok on a button, it adds the 'active' class; 2 - You click ok on another button the previous one should be with the "active"
– Alvaro Alves
is that it? in case click on it removes the 'active' class only from the current product?
– Alvaro Alves
exactly that!!!
– Maria
Let’s go continue this discussion in chat.
– Alvaro Alves