3 // Create 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 parseFloat( jQuery.css( this[0], type, "padding" ) ) :
15 // outerHeight and outerWidth
16 jQuery.fn["outer" + name] = function( margin ) {
18 parseFloat( jQuery.css( this[0], type, margin ? "margin" : "border" ) ) :
22 jQuery.fn[ type ] = function( size ) {
23 // Get window width or height
26 return size == null ? null : this;
29 if ( jQuery.isFunction( size ) ) {
30 return this.each(function( i ) {
31 var self = jQuery( this );
32 self[ type ]( size.call( this, i, self[ type ]() ) );
36 if ( jQuery.isWindow( elem ) ) {
37 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
38 // 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
39 var docElemProp = elem.document.documentElement[ "client" + name ];
40 return elem.document.compatMode === "CSS1Compat" && docElemProp ||
41 elem.document.body[ "client" + name ] || docElemProp;
43 // Get document width or height
44 } else if ( elem.nodeType === 9 ) {
45 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
47 elem.documentElement["client" + name],
48 elem.body["scroll" + name], elem.documentElement["scroll" + name],
49 elem.body["offset" + name], elem.documentElement["offset" + name]
52 // Get or set width or height on the element
53 } else if ( size === undefined ) {
54 var orig = jQuery.css( elem, type ),
55 ret = parseFloat( orig );
57 return jQuery.isNaN( ret ) ? orig : ret;
59 // Set the width or height on the element (default to pixels if value is unitless)
61 return this.css( type, typeof size === "string" ? size : size + "px" );