Jquery Wrap First N Number Of Elements Into One New Elements And Rest N Into Another New Element Using Slice
i am trying to wrap some elements within a div, logic goes like this if i have 10 div elements within one particular div, then first 5 elements should be wrapped within one new div
Solution 1:
You can use the following solution:
var templateNode = $('.multirow');
var divLength = $(templateNode).find('div').length;
var divL = Math.round(divLength / 2);
var nodes = $(templateNode).find('div'); // store all the nodes in one jQuery list
nodes.slice(0,divL).wrapAll('<div class="leftMost" />'); // wrap first half
nodes.slice(divL).wrapAll('<div class="rightMost" />'); // wrap remaining half
Post a Comment for "Jquery Wrap First N Number Of Elements Into One New Elements And Rest N Into Another New Element Using Slice"