Thursday, 19 September 2013

jQuery add "close & open" container to split list

jQuery add "close & open" container to split list

im trying to split a list via jQuery. I need some fix, because else the
navigation would crash my theme.
Heres my code, i already tried several things like append, after,
insertAfter. The problem is that jquery always adds the closing and reopen
tag in the right order - i need it the other way:
<ul>
<li>link here</li>
<li>link here</li>
<li>link here</li>
<li>link here</li>
</ul>
this is what i want:
<ul>
<li>link here</li>
<li>link here</li>
</ul><ul>
<li>link here</li>
<li>link here</li>
</ul>
this is my code so far:
var thirdLevelNavigation = $('ul.sub-menu').clone();
var countItems = 0;
thirdLevelNavigation.children('li').each(function() {
if(countItems == 5) {
// heres the trouble-maker
$('</ul><ul class="sub-menu">').insertAfter(this);
countItems = 0;
}
countItems++;
});
thirdLevelNavigation.appendTo('.menu-main-container');
(its a sub-nav tweak for multi dimensional wordpress navigations)
TIA!

No comments:

Post a Comment