Fixed #2077 by adding a var to make it a local variable instead of initializing a...
[jquery.git] / src / selector.js
index da27245..1badc69 100644 (file)
@@ -96,9 +96,9 @@ jQuery.extend({
                if ( typeof t != "string" )
                        return [ t ];
 
-               // Make sure that the context is a DOM Element
-               if ( context && !context.nodeType )
-                       context = null;
+               // check to make sure context is a DOM element or a document
+               if ( context && context.nodeType != 1 && context.nodeType != 9)
+                       return [ ];
 
                // Set the correct context (if none is provided)
                context = context || document;
@@ -140,7 +140,8 @@ jQuery.extend({
                                if ( (m = re.exec(t)) != null ) {
                                        r = [];
 
-                                       nodeName = m[2].toUpperCase(), merge = {};
+                                       var merge = {};
+                                       nodeName = m[2].toUpperCase();
                                        m = m[1];
 
                                        for ( var j = 0, rl = ret.length; j < rl; j++ ) {
@@ -320,7 +321,10 @@ jQuery.extend({
                        // :not() is a special case that can be optimized by
                        // keeping it out of the expression list
                        if ( m[1] == ":" && m[2] == "not" )
-                               r = jQuery.filter(m[3], r, true).r;
+                               // optimize if only one selector found (most common case)
+                               r = isSimple.test( m[3] ) ?
+                                       jQuery.filter(m[3], r, true).r :
+                                       jQuery( r ).not( m[3] );
 
                        // We can get a big speed boost by filtering by class here
                        else if ( m[1] == "." )