I have a page that returns a dynamic list of items
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
<li>item5</li>
<li>item6</li>
</ul>
I need a way to insert tags around every grouping of 3 list elements. Basically transform the code above into this
<ul>
<div>
<li>item1</li>
<li>item2</li>
<li>item3</li>
</div>
<div>
<li>item4</li>
<li>item5</li>
<li>item6</li>
</div>
</ul>
I have been playing around with the Jquery Wrap(),WrapAll(), WrapInner()... but with no success so far. Greatly appreciate any solutions or ideas on this.