diff --git a/src/offset.js b/src/offset.js index fcd39ed05..f8fd0ec87 100644 --- a/src/offset.js +++ b/src/offset.js @@ -138,7 +138,7 @@ jQuery.fn.extend({ while ( offsetParent && (!rroot.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) { offsetParent = offsetParent.offsetParent; } - return offsetParent; + return offsetParent || document.body; }); } }); diff --git a/test/index.html b/test/index.html index 9593e95a1..59dfad62d 100644 --- a/test/index.html +++ b/test/index.html @@ -305,6 +305,9 @@ Z
+ + + diff --git a/test/unit/offset.js b/test/unit/offset.js index 972c49f7c..6a6cbcff5 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -440,7 +440,7 @@ test("chaining", function() { }); test("offsetParent", function(){ - expect(11); + expect(12); var body = jQuery("body").offsetParent(); equal( body.length, 1, "Only one offsetParent found." ); @@ -464,6 +464,9 @@ test("offsetParent", function(){ equal( div.length, 2, "Two offsetParent found." ); equal( div[0], document.body, "The body is the offsetParent." ); equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); + + var area = jQuery("#imgmap area").offsetParent(); + equal( area[0], document.body, "The body is the offsetParent." ); }); test("fractions (see #7730 and #7885)", function() {