From: John Resig <jeresig@gmail.com>
Date: Wed, 25 Jul 2007 00:56:50 +0000 (+0000)
Subject: $("#foo", xml) would always return an empty set, fixed (bug #877). Additionally,... 
X-Git-Url: http://git.asbjorn.biz/?a=commitdiff_plain;h=f8b00051c377360f0106e56c24df1353aaf6ad44;p=jquery.git

$("#foo", xml) would always return an empty set, fixed (bug #877). Additionally, a bug in jQuery.isXMLDoc(xmlDoc) was discovered, if the element was, in fact, an XML document.
---

diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 8a2c6b2..6f4bbe3 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -1318,7 +1318,8 @@ jQuery.extend({
 	
 	// check if an element is in a XML document
 	isXMLDoc: function(elem) {
-		return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
+		return elem.documentElement && !elem.body ||
+			elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
 	},
 
 	nodeName: function( elem, name ) {
diff --git a/src/selector/selector.js b/src/selector/selector.js
index 2cf0b64..366cf31 100644
--- a/src/selector/selector.js
+++ b/src/selector/selector.js
@@ -213,7 +213,7 @@ jQuery.extend({
 					var elem = ret[ret.length-1];
 
 					// Try to do a global search by ID, where we can
-					if ( m[1] == "#" && elem && elem.getElementById ) {
+					if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
 						// Optimization for HTML document case
 						var oid = elem.getElementById(m[2]);