In the plugin that I am writing, I have terrible problems with the width of the table cells. All I do is get the width of the table cell using the jQuery .width() function, and then set the same cell as the returned width. Mainly:
$table.find('> thead > tr > th').each( function() { var $th = $(this); $th.css({width: $th.width()}); } );
However, in many cases, the returned width is incorrect and changing it changes the width of the cells. At first it seemed to me that it was disabled at 1px, so I added 1px to the returned width. But with tighter borders, it's bigger, but it doesn't seem to be just adding border widths. For starters, there are obviously two borders, but only with a width of 1 border. And with different border widths it seems almost random what value you need to add.
Here is an example with my code - part of the width setting starts 1 second after the page loads, so you can see the change. Is there a reliable way to get / set table cell widths in Javascript?
source share