I want to click on each button of each div
generated I take the data in which they are, the price and the name, but when the page is generated, all the buttons return the information of the first <div>
generated for the foreach...
<script type="text/javascript">
function data(){
var nombre = document.getElementById("nombre").innerHTML;
var precio = document.getElementById("precio").innerHTML;
alert(nombre+" "+precio);
}
</script>
So this is the block that is generated depending on the number of objects GPU
that they have:
<c:forEach items="${gpus}" var="gpus">
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<a href="#"><img class="card-img-top" src="${gpus.url}" alt=""></a>
<div class="card-body">
<h4 class="card-title">
<a id="nombre" href="">${gpus.nombre}</a>
</h4>
<h5 id="precio">$ ${gpus.precio}</h5>
<p class="card-text">${gpus.descripcion}</p>
</div>
<div class="card-footer">
<button type="button" onclick="data()"id="info" class="btn btn-success">Agregar al carrito</button>
</div>
</div>
</div>
</c:forEach>
[