views:

311

answers:

3

Is there a way of accessing the width of a DOM element? In particular, I'm looking to get the width of a table cell (td) who's width can be of varying lengths based on the length of the text in that cell.

ideally, the solution I'm looking for will use the jQuery library, but others will work as well.

Also, I must stress that the solution must work in IE6 (unfortunately :-P ) in addition to ie7, ie8, and firefox. Thanks in advance!!

+6  A: 
$('#td_id').width();

Of course you'll have to craft the selector to work with the cell in question, but otherwise it's that easy!

cpharmston
+3  A: 

Have you tried the 'width' method in jQuery?

SolutionYogi
+6  A: 

$(selector).width() should work fine, but make sure for IE6 and below that the page is rendered in Standards mode and not Quirks-Mode (so it follows W3C box model).

Here is some information on how to toggle Standard/Strict Mode:

CSS - Quirks mode and strict mode

Andrew Moore