Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
How to get dynamic id of div using loop in jquery

I am working with php and jquery,I am fetching following data in foreach loop

foreach start// "> id;?>"> coin_id;?>"> symbol;?>">

            <button id="getinfo" class="votess2" value="1"><img src="<?php echo base_url(); ?>/assets/img/thumb.png" height="40" width="30"></button>
            
            <button id="getinfo" class="votess2" value="0"><img src="<?php echo base_url(); ?>/assets/img/thumbdown.png" height="40" width="30"></button>
            
            
            </form>
    foreach ends//  
        

Now i want to use ajax after click on "like" "dislike" button but giving me always same "reviewId" instead of repeat,Where i am wrong ? Please help ,Thanks in advance

Here is my jquery code

<script type="text/javascript">
$(document).ready(function(){   
    
    
    $(".votess2").click(function()
    {   
    var WalletAddress = document.getElementById("WalletAddress").value;
    var ReviewId = document.getElementById("ReviewId").value;
     alert(ReviewId );

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you are using ID's inside a cicle (ex. foreach) you need to be carefull because the ID's will repeat. You can do set the onclick function on the input inside the foreach.

<?php
foreach($arr as $k=>$v) {
 $reviewID = $v->reviewID; //example because i dont know your array structure
?>
 <button id="getinfoUp<?=$k?>" onclick="thumbUp(<?=$k?>, <?=$reviewID?>)" class="votess2" value="1"><img src="<?php echo base_url(); ?>/assets/img/thumb.png" height="40" width="30"></button>
 <button id="getinfoDown<?=$k?>" onclick="thumbDown(<?=$k?>, <?=$reviewID?>)" class="votess2" value="0"><img src="<?php echo base_url(); ?>/assets/img/thumbdown.png" height="40" width="30"></button>
<?php } ?>

After that you just need to code the functions thumbUp and thumbDown in javascript.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda