Skip to content

Instantly share code, notes, and snippets.

@egorvinogradov
Created February 8, 2013 14:31
Show Gist options
  • Save egorvinogradov/4739343 to your computer and use it in GitHub Desktop.
Save egorvinogradov/4739343 to your computer and use it in GitHub Desktop.
Делает одинаковой ширину соответствующих колонок у таблиц, идущих друг под другом.
function get_max_width_array(tables){
var max_width_arr = [];
tables.each(function(i, table){
$(table).find('tr').first().find('th, td').each(function(i, td){
var width = $(td).width();
if ( !max_width_arr[i] || max_width_arr[i] < width ) {
max_width_arr[i] = width;
});
});
return max_width_arr;
};
var all_tables = $('table');
var width_arr = get_max_width_array(all_tables);
all_tables.each(function(i, table){
$(table).find('tr').first().find('th, td').each(function(i, td){
$(td).width(width_arr[i]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment