Last active
December 19, 2015 00:09
-
-
Save JAW-Dev/5866608 to your computer and use it in GitHub Desktop.
Split a list with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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