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

254
Views
How to get a specific attribute value content on each loop jquery

Can anyone tell me how I can get all the values on a specific attribute value on each loop ? I'm trying to get all the html values on each loop that has the specific attribute value( data-product=momentum-shorts ) <p>Two-Way Stretch </p> in this case..

This is my code

<script>
    jQuery( document ).ready(function() {
        $(".compare-main .compare-products").each(function(){
                $(this).each(function(){
                    console.log($(this).html());
                })
            });
        });
</script>

enter image description here

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use the jQuery attr() method

about 4 years ago · Juan Pablo Isaza Report

0

$(this).data('column') or $(this).data('product')

.data()

about 4 years ago · Juan Pablo Isaza Report

0

You can use the attribute equals selector :

$(".compare-main .compare-products [data-product='momentum-shorts']").each(function(){
  console.log($(this).html().trim());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="compare-main">
  <div class="compare-products">
    <div data-product="momentum-shorts">
      <p>Two-Way Stretch</p>
    </div>
    <div data-product="foo">
      <p>foo</p>
    </div>
  </div>
  <div class="compare-products">
    <div data-product="bar">
      <p>bar</p>
    </div>
    <div data-product="momentum-shorts">
      <p>Medium Weight</p>
    </div>
  </div>
</div>

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!