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

97
Visualizações
How to replace inner html onClick on each loop

I'm trying to loop each thru of the attribute and if it matches, it will replace the inner HTML of the DOM. For this example, I'm trying to replace the data-product="momentum-shorts-2-0" inner HTML DOM which is the <h2>Momentum Shorts 2.0 NEW</h2> contents into the <div> class="compare-main" </div> that I've highlighted in the screenshot..

This is what I have with my code now but i'm stuck.. it keeps returning to me singular value of the last item..

<script>
    jQuery( document ).ready(function() {
        
        $( ".compare-filter-item" ).click(function() {
            var selected_data_product = $(this).attr("data-product");
       
            
            $(".compare-all .compare-products [data-product='" + selected_data_product + "']").each(function(){
              
                new_html = $(this).html();
                $(".compare-main .compare-products [data-product='" + selected_data_product + "']").each(function(){
                    $(this).html(new_html);
                })
            });
             
        });

    })
</script>

enter image description here

Issue:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

<script>
    jQuery( document ).ready(function() {
        
        $( ".compare-filter-item" ).click(function() {
            var selected_data_product = "momentum-shorts-2-0";
       
            $(".compare-main .compare-products [data-product='" + selected_data_product + "']").each(function(){
                $(this).find("h2").text("Momentum Shorts 2.0");
            });
             
        });

    })
</script>

I tried to understand your requirement and here is the solution see if it help.

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