I have a long UL list I need to break up in smaller lists containing about 20 items each.
I was thinking I could use something like
$(function() {
$("ul li:nth-child(20n)").after("</ul><ul>");
});
but that's not the case. Any idea how to use jQuery in a way that uses minimal CPU?
Here's a working example, just change the mod 5 to mod 20.
you can try something like this:
LE: I think it can be further refined by finding up front how many new list will be createt, create those lists and move blocks of ~20 li's into the new created lists so they will be moved only once.
Just another version as a jQuery plugin:
function:
usage:
or:
I would create document fragments with your removed
li
s and then reappend them to the location you want them. In this case, I reappended them to the body:Live Demo is at: http://jsbin.com/ejigu/33
this one splits the menu in to pieces of approximately equal length function splitMenu(menu_id, pieces) {