Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda