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

98
Vistas
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 Respuestas
Responde la pregunta

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 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