From a8a6d4d815106dff926d5435ecf2b939e35ea8c3 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Thu, 19 Dec 2013 08:13:29 -0500 Subject: [PATCH] Synchronize .width() and .height() documentation * Include the style/script warning * Follow the style guide (http://contribute.jquery.org/style-guide/js/#comments) Ref jQuery #14545 --- entries/height.xml | 7 +++++-- entries/width.xml | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/entries/height.xml b/entries/height.xml index 3632ed02..08a2daf0 100644 --- a/entries/height.xml +++ b/entries/height.xml @@ -14,8 +14,11 @@

This method is also able to find the height of the window and document.


-$( window ).height(); // returns height of browser viewport
-$( document ).height(); // returns height of HTML document
+// Returns height of browser viewport
+$( window ).height();
+
+// Returns height of HTML document
+$( document ).height();
       

Note that .height() will always return the content height, regardless of the value of the CSS box-sizing property. As of jQuery 1.8, this may require retrieving the CSS height plus box-sizing property and then subtracting any potential border and padding on each element when the element has box-sizing: border-box. To avoid this penalty, use .css( "height" ) rather than .height().

diff --git a/entries/width.xml b/entries/width.xml index 9c49066e..ddc69ca0 100644 --- a/entries/width.xml +++ b/entries/width.xml @@ -21,6 +21,9 @@ $( window ).width(); $( 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. To avoid this penalty, use .css( "width" ) rather than .width().

+
+

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.

+
Show various widths. Note the values are from the iframe so might be smaller than you expected. The yellow highlight shows the iframe body.