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

76
Views
.nextUntil only return the first element it encounter

I currently have a block of html, I want to output the h4 and the block of text between the h4 and another h4 as a panel. So I can make a loop. This is what I have tried

<script type="text/template" id="product-details-temp">
 <div class="product-ddd">
    <h4>DETAILS &amp; DIMENSIONS</h4>
   <p>A trendy ...</p>
   <p>Made in the USA from...</p>
   <h4>FABRIC CONTENT &amp; CARE</h4>
   <p>Jacket / Tank:</p>
   <ul>
       <li>Hand Wash Cold</li>
       <li>No Chlorine</li>
       ...
   </ul>
   <h4>DETAILS &amp; OTHERS </h4>
 </div>
</script>
<script>    
   let titleArray = [];
   let textArray = [];
    let htmlTemplate = $("#product-details-temp").text();
    $(htmlTemplate).find('h4').each(function () {
        console.log($(this).nextUntil("h4").html());
        if ($(this).html() != undefined && $(this).nextUntil("h4").html() != undefined) {
            $(".product-panel-lists").append(
                '<div class="header">' + $(this).html() + '<i class="fas fa-chevron-down"></i></div><div class="panel">' + $(this).nextUntil("h4").html() + "</div>"
            );
        }
    });
</script>

It occur that the $(this).nextUntil("h4") only return the first element it encounter and ignore the rest until the next h4 and continue the iteration.

about 4 years ago · Juan Pablo Isaza
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!