I don't know how to put it in the title, but my problem is that I use a foreach to print an amount of data and repeat the card. I need to show an image by clicking on any image of the different cards that it brings. At the moment the jquery works for me only with the first card that it brings me, the others do not work for me. I attach the code.
<?php foreach ($validar as $v) { ?>
<div class="col-lg-4 col-md-6">
<div class="blog_post lyf">
<div class="img_podcconu">
<img class="imgpcard" src="https://pbs.twimg.com/profile_images/890901007387025408/oztASP4n.jpg" alt="random image">
</div>
<div class="container_copy">
<h3 class="h3card"><?= $v->nombre ?> <?= $v->apellido1 ?></br>
<i class="mdi mdi-email-variant"></i><?= $v->correo ?> </br>
<i class="mdi mdi-cellphone-android"></i><?= $v->celular ?> </br>
<i class="mdi mdi-account-multiple"></i><?= $v->user ?>
</h3></br>
<h1 class="h1card">Identificacion</h1>
<div class="espf">
<img id="myImg1" src="<?= base_url() ?>asset/images/confirmacion/<?= $v->img_cedula_front ?>" alt="Snow" style="width:100px;max-width:300px">
<img id="myImg2" src="<?= base_url() ?>asset/images/confirmacion/<?= $v->img_cedula_back ?>" alt="Snow" style="width:100px;max-width:300px">
<img id="myImg3" src="<?= base_url() ?>asset/images/confirmacion/<?= $v->img_selfie ?>" alt="Snow" style="width:100px;max-width:300px">
</div>
<div style="float: right;">
<button class="btn_primarycard btnc3">Aprobar</button>
<button type="button" class="btn waves-effect waves-light btn-outline-danger">Danger</button>
</div>
</div>
</div>
</div>
<?php } ?>
and this is the jquery that makes me the process
$("#myImg1").on("click", function() {
id = $(this).attr("src");
$('#myModal').show(); //muestro mediante id
$('#img01').attr("src",id);
});
$("#myImg2").on("click", function() {
id = $(this).attr("src");
$('#myModal').show(); //muestro mediante id
$('#img01').attr("src",id);
});
$("#myImg3").on("click", function() {
id = $(this).attr("src");
$('#myModal').show(); //muestro mediante id
$('#img01').attr("src",id);
});
I placed everything inside the foreach so that I can identify and place different id