Last active
March 8, 2018 23:13
-
-
Save adeishs/b259fcd57230a36c7a1cce4bf89386cc to your computer and use it in GitHub Desktop.
Lining Up Table Columns 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
<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