3 // Create width, height, innerHeight, innerWidth, outerHeight and outerWidth methods
4 jQuery.each([ "Height", "Width" ], function( i, name ) {
6 var type = name.toLowerCase();
8 // innerHeight and innerWidth
9 jQuery.fn[ "inner" + name ] = function() {
11 return elem && elem.style ?
12 parseFloat( jQuery.css( elem, type, "padding" ) ) :
16 // outerHeight and outerWidth
17 jQuery.fn[ "outer" + name ] = function( margin ) {
19 return elem && elem.style ?
20 parseFloat( jQuery.css( elem, type, margin ? "margin" : "border" ) ) :
24 jQuery.fn[ type ] = function( size ) {
25 // Get window width or height
28 return size == null ? null : this;
31 if ( jQuery.isFunction( size ) ) {
32 return this.each(function( i ) {
33 var self = jQuery( this );
34 self[ type ]( size.call( this, i, self[ type ]() ) );
38 if ( jQuery.isWindow( elem ) ) {
39 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
40 // 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
41 var docElemProp = elem.document.documentElement[ "client" + name ],
42 body = elem.document.body;
43 return elem.document.compatMode === "CSS1Compat" && docElemProp ||
44 body && body[ "client" + name ] || docElemProp;
46 // Get document width or height
47 } else if ( elem.nodeType === 9 ) {
48 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
50 elem.documentElement["client" + name],
51 elem.body["scroll" + name], elem.documentElement["scroll" + name],
52 elem.body["offset" + name], elem.documentElement["offset" + name]
55 // Get or set width or height on the element
56 } else if ( size === undefined ) {
57 var orig = jQuery.css( elem, type ),
58 ret = parseFloat( orig );
60 return jQuery.isNaN( ret ) ? orig : ret;
62 // Set the width or height on the element (default to pixels if value is unitless)
64 return this.css( type, typeof size === "string" ? size : size + "px" );