How to create a table with the same dimensions as a previous one

advertisements

I would want to create a table with the same widths (table and its cells) then a previous one created dynamically

1st

__________________
|_____|___|_______|
|_____|___|_______|
|_____|___|_______|

2nd

__________________
|_____|___|_______|
|_____|___|_______|

What do I need to do to set the second one with the desired widths. (Table 1 widths depends on it's content).

Edit: Finally, I went for the jQuery solution and did it like that:

  $("#mySecondTable tr") // mySecondTable was already generated server side
  .first() // All rows in my second table are similar so I just apply on the first one
  .find("td")
  .width(function(i){ return $("#myFirstTable tr").eq(1).find("td").eq(i).width() })
  // eq(1) fetches the line I want to use as a model since some have different colspans
  .end()


You could accomplish this with jQuery pretty easily:

$("table.foo")
  .clone()
    .find("td")
      .html("")
      .width(function(i){ return $("table.foo td").eq(i).width() })
      .height(function(i){ return $("table.foo td").eq(i).height() })
    .end()
  .appendTo("body");

Online Demo: http://jsbin.com/obuco/3/edit