]> source.dussan.org Git - jquery.git/commitdiff
Make sure closest works on disconnected DOM nodes. Fixes #7142.
authorJohn Resig <jeresig@gmail.com>
Mon, 11 Oct 2010 11:45:15 +0000 (07:45 -0400)
committerJohn Resig <jeresig@gmail.com>
Mon, 11 Oct 2010 11:45:15 +0000 (07:45 -0400)
src/traversing.js
test/unit/traversing.js

index de250e6c64fe4660f9c0450f3d2be98100c86dc1..5a479f2efc47825670905bbbfaaa4c7af3b2d130 100644 (file)
@@ -108,7 +108,7 @@ jQuery.fn.extend({
 
                                } else {
                                        cur = cur.parentNode;
-                                       if ( !cur.ownerDocument || cur === context ) {
+                                       if ( !cur || !cur.ownerDocument || cur === context ) {
                                                break;
                                        }
                                }
index 0636f0c33e2ac6defc180d9fcc76e08a09c4978d..f9e79372a761cc2196a04023a9399680b211925e 100644 (file)
@@ -122,7 +122,7 @@ test("filter(jQuery)", function() {
 })
 
 test("closest()", function() {
-       expect(10);
+       expect(11);
        same( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
        same( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
        same( jQuery("body").closest("div").get(), [], "closest(div)" );
@@ -139,7 +139,9 @@ test("closest()", function() {
        
        //Test that .closest() returns unique'd set
        equals( jQuery('#main p').closest('#main').length, 1, "Closest should return a unique set" );
-       
+
+       // Test on disconnected node
+       equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
 });
 
 test("closest(Array)", function() {