Moak
Moak

Reputation: 12865

How do you get the width of an element without a defined width?

How would you find out the width of a element that is wrapped by 20 odd other elements, but the only fixed width I know is the main wrapper's which is 800px. All child elements are generally blocks, floating or not, with different paddings and margins.
I don't really need the answer to a specific case, I'm just wondering if there are tools or tricks to quickly calculate such things.
Thanks

EDIT: Sorry to forget, this is on an external site where I can not install any scripts or edit the css.

Upvotes: 1

Views: 192

Answers (4)

BalusC
BalusC

Reputation: 1108537

You need to use element.offsetWidth.

var width = element.offsetWidth;

Upvotes: 3

Pekka
Pekka

Reputation: 449385

jQuery has width() that allows to find out the width of any DOM element reliably across browsers. Does that help?

Upvotes: 3

Sarfraz
Sarfraz

Reputation: 382606

You can put JQuery to use and use its width() method for that. The jQuery is smart enough to get the computed width of the element you specify.

Upvotes: 2

Related Questions