selector = selector.replace( Expr.match.POS, "" );
                        }
 
-                       set = Sizzle.filter( later, Sizzle( selector, context ) );
+                       set = Sizzle.filter( later, Sizzle( /\s$/.test(selector) ? selector + "*" : selector, context ) );
                } else {
                        set = Expr.relative[ parts[0] ] ?
                                [ context ] :
                ID: /#((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,
                CLASS: /\.((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,
                NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF_-]|\\.)+)['"]*\]/,
-               ATTR: /\[((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\]/,
+               ATTR: /\[\s*((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
                TAG: /^((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)/,
                CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,
                POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,
                "class": "className",
                "for": "htmlFor"
        },
+       attrHandle: {
+               href: function(elem){
+                       return elem.getAttribute("href");
+               }
+       },
        relative: {
                "+": function(checkSet, part){
                        for ( var i = 0, l = checkSet.length; i < l; i++ ) {
                                checkFn = dirNodeCheck;
                        }
 
-                       checkFn("parentNode", part, doneName, checkSet, nodeCheck);
+                       checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
                },
                "~": function(checkSet, part, isXML){
                        var doneName = "done" + (done++), checkFn = dirCheck;
                                checkFn = dirNodeCheck;
                        }
 
-                       checkFn("previousSibling", part, doneName, checkSet, nodeCheck);
+                       checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
                }
        },
        find: {
                        return match.test( elem.className );
                },
                ATTR: function(elem, match){
-                       var result = elem[ match[1] ] || elem.getAttribute( match[1] ), value = result + "", type = match[2], check = match[4];
+                       var result = Expr.attrHandle[ match[1] ] ? Expr.attrHandle[ match[1] ]( elem ) : elem[ match[1] ] || elem.getAttribute( match[1] ), value = result + "", type = match[2], check = match[4];
                        return result == null ?
                                false :
                                type === "=" ?
        root.removeChild( form );
 })();
 
-// Check to see if the browser returns only elements
-// when doing getElementsByTagName("*")
 (function(){
+       // Check to see if the browser returns only elements
+       // when doing getElementsByTagName("*")
+
        // Create a fake element
        var div = document.createElement("div");
        div.appendChild( document.createComment("") );
                        return results;
                };
        }
+
+       // Check to see if an attribute returns normalized href attributes
+       div.innerHTML = "<a href='#'></a>";
+       if ( div.firstChild.getAttribute("href") !== "#" ) {
+               Expr.attrHandle.href = function(elem){
+                       return elem.getAttribute("href", 2);
+               };
+       }
 })();
 
 if ( document.querySelectorAll ) (function(){
        };
 }
 
-function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck ) {
+function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
        for ( var i = 0, l = checkSet.length; i < l; i++ ) {
                var elem = checkSet[i];
                if ( elem ) {
                                        break;
                                }
 
-                               if ( elem.nodeType === 1 )
+                               if ( elem.nodeType === 1 && !isXML )
                                        elem[doneName] = i;
 
                                if ( elem.nodeName === cur ) {
        }
 }
 
-function dirCheck( dir, cur, doneName, checkSet, nodeCheck ) {
+function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
        for ( var i = 0, l = checkSet.length; i < l; i++ ) {
                var elem = checkSet[i];
                if ( elem ) {
                                }
 
                                if ( elem.nodeType === 1 ) {
-                                       elem[doneName] = i;
+                                       if ( !isXML )
+                                               elem[doneName] = i;
 
                                        if ( typeof cur !== "string" ) {
                                                if ( elem === cur ) {
 
 
 test("element", function() {
        expect(9);
+       reset();
+
        ok( jQuery("*").size() >= 30, "Select all" );
        var all = jQuery("*"), good = true;
        for ( var i = 0; i < all.length; i++ )
                                name + ": " + selector );
                }
        }
-
+       
        broken( "Broken Selector", "[", [] );
        broken( "Broken Selector", "(", [] );
        broken( "Broken Selector", "{", [] );
 });
 
 test("child and adjacent", function() {
-       expect(38);
+       expect(41);
        t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
        t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
        t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
        t( "Adjacent", "p + p", ["ap","en","sap"] );
        t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
 
+       isSet( jQuery("> :first", document.getElementById("nothiddendiv")), q("nothiddendivchild"), "Verify child context positional selctor" );
+       isSet( jQuery("> :eq(0)", document.getElementById("nothiddendiv")), q("nothiddendivchild"), "Verify child context positional selctor" );
+       isSet( jQuery("> *:first", document.getElementById("nothiddendiv")), q("nothiddendivchild"), "Verify child context positional selctor" );
+
        t( "Non-existant ancestors", ".fototab > .thumbnails > a", [] );
        
        t( "First Child", "p:first-child", ["firstp","sndp"] );
        t( "Last Child", "p:last-child", ["sap"] );
        t( "Last Child", "a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon"] );
        
-       t( "Nth-child", "#main form#form > *:nth-child(2)", ["text2"] );
-       t( "Nth-child", "#main form#form > :nth-child(2)", ["text2"] );
+       t( "Nth-child", "#main form#form > *:nth-child(2)", ["text1"] );
+       t( "Nth-child", "#main form#form > :nth-child(2)", ["text1"] );
 
        t( "Nth-child", "#form select:first option:nth-child(3)", ["option1c"] );
        t( "Nth-child", "#form select:first option:nth-child(0n+3)", ["option1c"] );
 });
 
 test("attributes", function() {
-       expect(21);
+       expect(27);
        t( "Attribute Exists", "a[title]", ["google"] );
        t( "Attribute Exists", "*[title]", ["google"] );
        t( "Attribute Exists", "[title]", ["google"] );
+       t( "Attribute Exists", "a[ title ]", ["google"] );
        
        t( "Attribute Equals", "a[rel='bookmark']", ["simon1"] );
        t( "Attribute Equals", 'a[rel="bookmark"]', ["simon1"] );
        t( "Attribute Equals", "a[rel=bookmark]", ["simon1"] );
        t( "Attribute Equals", "a[href='http://www.google.com/']", ["google"] );
+       t( "Attribute Equals", "a[ rel = 'bookmark' ]", ["simon1"] );
+
+       document.getElementById("anchor2").href = "#2";
+       t( "href Attribute", "p a[href^=#]", ["anchor2"] );
+       t( "href Attribute", "p a[href*=#]", ["simon1", "anchor2"] );
+
+       t( "for Attribute", "form label[for]", ["label-for"] );
+       t( "for Attribute in form", "#form [for=action]", ["label-for"] );
        
        var results = ["hidden1","radio1","radio2"];