Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!