diff --git a/src/css.js b/src/css.js index 2a82b3845..0c966c6f4 100644 --- a/src/css.js +++ b/src/css.js @@ -437,12 +437,21 @@ jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight, jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft, function( elem, computed ) { if ( computed ) { - return ( parseFloat( curCSS( elem, "marginLeft" ) ) || - elem.getBoundingClientRect().left - - swap( elem, { marginLeft: 0 }, function() { - return elem.getBoundingClientRect().left; - } ) - ) + "px"; + return ( + parseFloat( curCSS( elem, "marginLeft" ) ) || + + // Support: IE<=11+ + // Running getBoundingClientRect on a disconnected node in IE throws an error + // Support: IE8 only + // getClientRects() errors on disconnected elems + ( jQuery.contains( elem.ownerDocument, elem ) ? + elem.getBoundingClientRect().left - + swap( elem, { marginLeft: 0 }, function() { + return elem.getBoundingClientRect().left; + } ) : + 0 + ) + ) + "px"; } } );