Skip to content

Instantly share code, notes, and snippets.

@JAW-Dev
Last active December 19, 2015 00:09
Show Gist options
  • Save JAW-Dev/5866608 to your computer and use it in GitHub Desktop.
Save JAW-Dev/5866608 to your computer and use it in GitHub Desktop.
Split a list with jQuery
$(function() {
$("ul").each(function() {
var list = $(this);
var size = 3;
var current_size = 0;
list.children().each(function() {
console.log(current_size + ": " + $(this).text());
if (++current_size > size) {
var new_list = $("<ul></ul>").insertAfter(list);
list = new_list;
current_size = 1;
}
list.append(this);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment