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 extension of the jQuery prototype ($.fn) object to provide a new method that can be chained to the jQuery() function.
I needed to functionality where I needed to add an element between the list that I split. That has been added as an optional parameter.
An example is available at http://jsfiddle.net/roeburg/5F2hW/
The usage of the function is like so:
The function is defined as follows:
Hope this helps.
Nothing quite that simple (that I'm aware of at least) unfortunately. Try this as an alternative:
You could no doubt turn this into a function that takes the chunk size as an argument but I leave that as an exercise for the reader.
Something like this:
Working Demo
Here is another option - I haven't profiled any of the above, so go with whatever is fastest of course. It assumes the ul in question has the id of #list.