开发者

Get the width in pixels of an element using jquery

I want to get the width of an element including border, margin and padding.

I know using $(input).width() or $(input).css('width') give the width of the element.

But here is the requirement.

Suppose I created a text box like follows:

<input type='text' id='txtBox' name='txtBox' style='width:100%' />

or

<input type='text' id='txtBox' name='txtBox' style='width:auto' />

If I get the width using either $input.css('width') or $input.width(). I am not able to get the 开发者_StackOverflow中文版width in pixels. I am using jquery1.3.2.


That should work just fine.

You are maybe missing to wrap your code into jQuery(document).ready().

See. http://www.jsfiddle.net/Cs4bu/1/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜