Added some additional checks to make sure that the correct methods are being used...
[jquery.git] / src / selector.js
index a250746..6b9152d 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Sizzle CSS Selector Engine - v0.9.1
+ * Sizzle CSS Selector Engine - v0.9.2
  *  Copyright 2009, The Dojo Foundation
  *  Released under the MIT, BSD, and GPL Licenses.
  *  More information: http://sizzlejs.com/
@@ -655,15 +655,15 @@ try {
        // The workaround has to do additional checks after a getElementById
        // Which slows things down for other browsers (hence the branching)
        if ( !!document.getElementById( id ) ) {
-               Expr.find.ID = function(match, context){
-                       if ( context.getElementById ) {
+               Expr.find.ID = function(match, context, isXML){
+                       if ( typeof context.getElementById !== "undefined" && !isXML ) {
                                var m = context.getElementById(match[1]);
-                               return m ? m.id === match[1] || m.getAttributeNode && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
+                               return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
                        }
                };
 
                Expr.filter.ID = function(elem, match){
-                       var node = elem.getAttributeNode && elem.getAttributeNode("id");
+                       var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
                        return elem.nodeType === 1 && node && node.nodeValue === match;
                };
        }
@@ -723,7 +723,9 @@ if ( document.querySelectorAll ) (function(){
        Sizzle = function(query, context, extra, seed){
                context = context || document;
 
-               if ( !seed && context.nodeType === 9 ) {
+               // Only use querySelectorAll on non-XML documents
+               // (ID selectors don't work in non-HTML documents)
+               if ( !seed && context.nodeType === 9 && !isXML(context) ) {
                        try {
                                return makeArray( context.querySelectorAll(query), extra );
                        } catch(e){}