function wrapEach(element, wrapper, countToWrap) {
var elements = Array.apply(null, document.querySelectorAll(element));
var parent = elements[0].parentNode;
var counter = 0;
var container = null;
for (var i = 0; i < elements.length; i++) {
if (counter == 0) {
container = document.createElement(wrapper);
container.classList.add('row');
}
container.appendChild(elements[i]);
if (counter + 1 == countToWrap || i + 1 == elements.length) {
counter = 0;
parent.appendChild(container);
continue;
}
counter++;
}
}
wrapEach('.item', 'div', 4);
так??? непомогло(((