I need to change the color of a button in a product list. However, I get in a variable another list with the product id only from the logged in user. Structure I get:
[2, 7, 18, 21] // are the user ids of the logged in user
Based on this, I wanted to know how I can change, using JQuery the color of the button in the list below, according to the product id of the list below, is equal to the list of the structure above.
My product list is:
<table id="produtos">
<thead>
<tr>
<th>Nome</th>
<th>Usuário</th>
<th>Quantidade</th>
</tr>
</thead
<tbody>
<c:forEach items="${produtos}" var="p">
<tr>
<td>${p.nome }</td>
<td>${p.usuario.nome }</td>
<td>${p.quantidade}</td>
<td>
<form id="testeForm" action="<c:url value="/atualizaQuantidade"/>" method="post" >
<input type="hidden" name="produto.cod" id="cod" value="${p.cod}" />
<button type="submit" class="btn btn-primary"></button>
</form>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
By matching the "Id", change the color of the button. My table then displays the product name, user name, and quantity. I put a button to update, but I wanted it to have a different color if the user responsible for that product was logged in.
Example: user with id 7 logged in, only his products the button would be in the green color (example), not being his, the current color of the button remained.
Thank you