I’m using a bit of code suggested by a member on stackoverflow and adapted by me to wrap every 3 list items as part of a mega menu. The code is:
var lis = $("ul > li");
for(var i = 0; i < ls.length; i+=3) {
lis.slice(i, i+3).wrapAll("<div class='new'></div>");
}
Unfortunately this will grab child li’s from the next parent menu to fill up the ‘quota’ of 3 li’s in a div. This is of course massively messing up my menus. For an example please visit here.
Does anyone have any suggestion how I could fix this up?
Your problem is your selector. Since
sizzleworks right to left, it will just query allLI elementswhich have anUL elementas direct parent (which usually, is always the case).So, seperate your
ULs.