Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lining Up Table Columns with jQuery
<script type="text/javascript">
$(function() {
var widths = new Array;
/* get max column widths from tables */
$('table').each(function() {
i = 0;
$(this).find('thead th').each(function() {
w = $(this).width();
if (!widths[i]) {
widths[i] = 0;
}
if (w > widths[i]) {
widths[i] = w;
}
++i;
});
});
/* now that we have got the max column widths, apply them
* to all tables so that the columns line up
*/
$('table').each(function() {
i = 0;
$(this).find('thead th').each(function() {
$(this).width(widths[i++]);
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.