Skip to content

Instantly share code, notes, and snippets.

@adeishs
Last active March 8, 2018 23:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save adeishs/b259fcd57230a36c7a1cce4bf89386cc to your computer and use it in GitHub Desktop.
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