Is it possible to use nth-child
selectors to wrap 3 divs using .wrapAll
? I can\'t seem to work out the correct equation.
so...
I have prepared this answer for another question that was duplicate of this one. So maybe my variant will be usefull for some one:
I think the solution to wrap all three elements is:
var $lines = $('.w-col'), // All Dom elelements with class .w-col
holder = []; //Collect DOM elelements
$lines.each(function (i, item) {
holder.push(item);
if (holder.length === 3) {
$(holder).wrapAll('');
holder.length = 0;
}
});
$(holder).wrapAll(''); //Wrap last elements with div(class=w-row)
I have wrote the same code at jsbin with some improvements http://jsbin.com/necozu/17/ or http://jsbin.com/necozu/16/