开发者

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

How would you find 开发者_JAVA技巧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.


Firebug is your friend.

How do you get the width of an element without a defined width? - Stack Overflow http://img.skitch.com/20100426-nequkipg8ex3khs1mux3tnctjb.preview.jpg


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


You need to use element.offsetWidth.

var width = element.offsetWidth;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜