How do I get the width of a box in jQuery?

$ (document).width (); Note that.width () will always return the content width, regardless of the value of the CSS box-sizing property. As of jQuery 1.8, this may require retrieving the CSS width plus box-sizing property and then subtracting any potential border and padding on each element when the element has box-sizing: border-box.

Is jQuery still using this method for document height/width calculation?

@StayCool it seems that the most recent jQuery is still using this method for the document height/width calculation and it gives the same result as $(document).width(). Maybe you are after something like $(window).width()which in pure JS would be just document.documentElement[“clientWidth\\on modern browsers.

What is the use of width in HTML?

Definition and Usage. The width() method sets or returns the width of the selected elements. When this method is used to return width, it returns the width of the FIRST matched element. When this method is used to set width, it sets the width of ALL matched elements.

How to find the width of the window and document?

The .width () method is recommended when an element’s width needs to be used in a mathematical calculation. This method is also able to find the width of the window and document.

How do I get the content width of a box-sizing element?

$( document ).width(); Note that .width() will always return the content width, regardless of the value of the CSS box-sizing property. As of jQuery 1.8, this may require retrieving the CSS width plus box-sizing property and then subtracting any potential border and padding on each element when the element has box-sizing: border-box.

Can I call width() or height() methods on a display block?

Note: Although style and script tags will report a value for .width () or height () when absolutely positioned and given display:block, it is strongly discouraged to call those methods on these tags. In addition to being a bad practice, the results may also prove unreliable.

You Might Also Like