-1

In Business Catalyst I have a div that outputs an unordered list. I need to out a separate div of non-unordered items after every 4th item. The hard coded version looks like this:

<div class="article-list">
 <ul class="article-list grid">
   <li>Item 1</li>
   <li>Item 2</li>
   <li>Item 3</li>
   <li>Item 4</li>
 </ul>

<div class="sponsored-post">
 <ul class="sponsored-post grid">
   <li>Hardcoded Item 1</li>
   <li>Hardcoded Item 2</li>
 </ul>
</div>

<div class="article-list">
 <ul class="article-list grid">
   <li>Item 5</li>
   <li>Item 6</li>
   <li>Item 7</li>
   <li>Item 8</li>
 </ul>
</div>
  • 2
    Welcome to StackOverflow. Please note that we do not provide you code. We only help you if you have tried something, and stuck with specific technical issues. – karthikr Jun 30 '14 at 03:22
  • This isn't really very easy to understand, you have an unordered list, and now you want it "non-unordered", which in english means ordered, but ordered how exactly, and what should happen every fourth item ? – adeneo Jun 30 '14 at 03:24

1 Answers1

0

Use jQuery .each() and keep track of a variable in your loop. If that counter is divisible by 4, then append a div to the <li>

$(".article-list").each(function(i, value) {
    if(i % 4 == 0) {
        newDiv = $("<div></div>").html("new div");
        $(this).append(newDiv);
    }
});