I have a series of div
elements in my HTML code:
<div class="mainClass class_1"></div>
<div class="mainClass class_1"></div>
<div class="mainClass class_2"></div>
<div class="mainClass class_2"></div>
<div class="mainClass class_2"></div>
<div class="mainClass class_2"></div>
<div class="mainClass class_3"></div>
<div class="mainClass class_3"></div>
<div class="mainClass class_3"></div>
<div class="mainClass class_4"></div>
<div class="mainClass class_4"></div>
I am looking to organize them as follows:
<div class="wrapper">
<div class="mainClass class_1"></div>
<div class="mainClass class_1"></div
</div>
<div class="wrapper">
<div class="mainClass class_2"></div>
<div class="mainClass class_2"></div>
<div class="mainClass class_2"></div>
<div class="mainClass class_2"></div>
</div>
<div class="wrapper">
<div class="mainClass class_3"></div>
<div class="mainClass class_3"></div>
<div class="mainClass class_3"></div>
</div>
<div class="wrapper">
<div class="mainClass class_4"></div>
<div class="mainClass class_4"></div>
</div>
How can I achieve this layout using an each loop and wrapAll
(or any other method) with jQuery?
I want to avoid manually adding the wrapper for each class (class_1, class_2, class_3 ... ).
Thank you for your assistance!