diff --git a/src/traversing.js b/src/traversing.js index fe2e33d8..468aa097 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -112,7 +112,7 @@ jQuery.fn.extend({ } else { cur = cur.parentNode; - if ( !cur || !cur.ownerDocument || cur === context ) { + if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) { break; } } diff --git a/test/unit/traversing.js b/test/unit/traversing.js index f5108bde..4cccd650 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -124,7 +124,7 @@ test("filter(jQuery)", function() { }) test("closest()", function() { - expect(11); + expect(13); 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)" ); @@ -144,6 +144,10 @@ test("closest()", function() { // Test on disconnected node equals( jQuery("

").find("p").closest("table").length, 0, "Make sure disconnected closest work." ); + + // Bug #7369 + equals( jQuery('
').closest('[foo]').length, 1, "Disconnected nodes with attribute selector" ); + equals( jQuery('
text
').closest('[lang]').length, 0, "Disconnected nodes with text and non-existent attribute selector" ); }); test("closest(Array)", function() {