I have the below html structure:
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div class="thumbnail"></div>
Now to group/wrap each 4 items in a separate div I did as below:
var div=$('.thumbnail');
for(var i = 0; i < div.length; i+=4) {
div.slice(i, i+4).wrapAll("<div class='new'></div>");
};
My question - Is there any way to convert this specific loop into $.each or is for loop only the way to do this?
UPDATE
This ain't duplicate because the answer mentioned there using jquery
$.eachdoesn't work as expected and that has been specific to wrappingdivsmay be on any technique and my question is specific to wrap with$.each. I don't see it as duplicate!!
A Pen to show how the $.each answer over there works!