Skip to content

Instantly share code, notes, and snippets.

@sbp
Created August 14, 2011 22:52
Show Gist options
  • Save sbp/1145414 to your computer and use it in GitHub Desktop.
Save sbp/1145414 to your computer and use it in GitHub Desktop.
jQuery to break a list into two table columns
$(function() {
$('ul.break').each(function() {
var ul = $(this);
var table = $('<table><tr></tr></table>');
table.addClass('spread');
var a = $('<td><ul></ul></td>');
var b = $('<td><ul></ul></td>');
$('tr', table).append(a);
$('tr', table).append(b);
var left = $('ul', a);
var right = $('ul', b);
var half = (($('li', ul).size() + 1) / 2) - 1;
$('li', ul).each(function(i, li) {
if (i <= half) {
$(li).appendTo(left);
} else { $(li).appendTo(right); }
});
ul.replaceWith(table);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment