From aaf134bb7092efe7b450fc08ca5cc3c53cb00d76 Mon Sep 17 00:00:00 2001 From: Nowres Rafid Date: Fri, 6 Jul 2012 09:58:34 -0400 Subject: [PATCH] Fix #8482, offsetParent should not return null. Closes gh-847. --- src/offset.js | 2 +- test/index.html | 3 +++ test/unit/offset.js | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) 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() { -- 2.39.5