diff options
author | John Resig <jeresig@gmail.com> | 2010-09-28 10:55:48 -0400 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2010-09-28 10:55:48 -0400 |
commit | cf672a2e7a886cac5ae62f6772c6b4b43b19a2fc (patch) | |
tree | f8e93b0849a7c51babe442b197d1dbf4aaa84204 /src/offset.js | |
parent | 7be11207b9267592a639eb739dc8d719c7de56a1 (diff) | |
download | jquery-cf672a2e7a886cac5ae62f6772c6b4b43b19a2fc.tar.gz jquery-cf672a2e7a886cac5ae62f6772c6b4b43b19a2fc.zip |
Make sure that .offset() doesn't fail against disconnected DOM nodes. Fixes #4996.
Diffstat (limited to 'src/offset.js')
-rw-r--r-- | src/offset.js | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/offset.js b/src/offset.js index 650cc08e9..39763ee60 100644 --- a/src/offset.js +++ b/src/offset.js @@ -5,7 +5,7 @@ var rtable = /^t(?:able|d|h)$/i, if ( "getBoundingClientRect" in document.documentElement ) { jQuery.fn.offset = function( options ) { - var elem = this[0]; + var elem = this[0], box; if ( options ) { return this.each(function( i ) { @@ -21,8 +21,14 @@ if ( "getBoundingClientRect" in document.documentElement ) { return jQuery.offset.bodyOffset( elem ); } - var box = elem.getBoundingClientRect(), - doc = elem.ownerDocument, + try { + box = elem.getBoundingClientRect(); + + } catch(e) { + box = { top: elem.offsetTop, left: elem.offsetLeft }; + } + + var doc = elem.ownerDocument, body = doc.body, docElem = doc.documentElement, win = getWindow(doc), |