Created
August 14, 2011 22:52
-
-
Save sbp/1145414 to your computer and use it in GitHub Desktop.
jQuery to break a list into two table columns
This file contains hidden or 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.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