2

I have a big -list with lots of li-elements. I want to split the ul-list into multiple ul lists with jquery.

To mark at which li element I want to start a new ul list I have inserted a class="column_break".

Do you have a hint for me – how I can separate the list and insert a new ul-element?

Is-Status:

<ul class="list--column">
   <li id="menu-item-1" class="column-break"><a href="#"> First colum</a> </li>
   <li id="menu-item-2"><a href="#"> pizza</a> </li>
   <li id="menu-item-3"><a href="#"> ice crem </a> </li>
   <li id="menu-item-4"><a href="#"> salad </a> </li>
   <li id="menu-item-5"><a href="#"> pasta </a> </li>

   <li id="menu-item-9" class="column-break"><a>Second column</a>   </li>
   <li id="menu-item-10"><a href="#"> Coffee </a>  </li>
   <li id="menu-item-11"><a href="#"> Orange Juice </a> </li>
   <li id="menu-item-12"><a href="#" > Cola </a>  </li>
</ul>

Should-Status:

<ul class="list--column">
   <li id="menu-item-1" class="column_break"><a href="#"> First colum</a> </li>
   <li id="menu-item-2"><a href="#"> pizza</a> </li>
   <li id="menu-item-3"><a href="#"> ice crem </a> </li>
   <li id="menu-item-4"><a href="#"> salad </a> </li>
   <li id="menu-item-5"><a href="#"> pasta </a> </li>
</ul><ul class="list--column">
   <li id="menu-item-9" class="column_break"><a>Second column</a>   </li>
   <li id="menu-item-10"><a href="#"> Coffee </a>  </li>
   <li id="menu-item-11"><a href="#"> Orange Juice </a> </li>
   <li id="menu-item-12"><a href="#" > Cola </a>  </li>
</ul>

I wanted to implement it with this code lines, but this is not working:

  $wrapper.children(".column-break").each(function(i,item) {
        var $following = $(item).nextUntil(".column_break");
        $wrapper.append($("<ul class='list--column'></ul>").append(item, $following));
   });
S.Tiger
  • 43
  • 5
  • Is there a reason you want two
      elements? Making two columns out of the current HTML would be easier with just CSS.
      – Eriks Klotins Aug 24 '20 at 12:53
    • yes - I want to have a new column at a specific
    • -element because some li elements should stay together and not start in a new column.
    • – S.Tiger Aug 24 '20 at 12:55