开发者

Size of DOM element when in it's "auto"

How i can get the wi开发者_如何学JAVAdth or height of DOM element when in CSS it's size is auto? When i try use

$("#element_id").width();
$("#element_id").height();

it returns zero. So i need the real size of the element.


As stated above the .width() and . height() should be computed values.

You will have problems if the items are displayed none or if they are not taking up the width you would expect them to. this could be due to the elements not being floated or similar.

A good way to see what the width or height of an element should be is to use firebug in firefox.

once you select an element click on either the Computed or the layout tabs on the right in there you will see the values for the selected element, when you hover the element in the tree view it will also should you what space the element is taking up on the page.


I put a source code at this link http://jsfiddle.net/F42Rx/.

You can see that I put the div with an auto width and made an alert that shows that it returns the computed width.

Regards


I solves the problem. As already said the item was set display: none. So I set the CSS property to hidden: hidden. And everything works fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜