Commit 28a1f022 authored by John Resig's avatar John Resig

Re-worked the logic for where .selector and .context are added for ID...

Re-worked the logic for where .selector and .context are added for ID selectors (especially ones that aren't found). Fixes jQuery bug #3833.
parent 7647cebc
...@@ -47,20 +47,16 @@ jQuery.fn = jQuery.prototype = { ...@@ -47,20 +47,16 @@ jQuery.fn = jQuery.prototype = {
else { else {
var elem = document.getElementById( match[3] ); var elem = document.getElementById( match[3] );
// Make sure an element was located // Handle the case where IE and Opera return items
if ( elem ){ // by name instead of ID
// Handle the case where IE and Opera return items if ( elem && elem.id != match[3] )
// by name instead of ID return jQuery().find( selector );
if ( elem.id != match[3] )
return jQuery().find( selector ); // Otherwise, we inject the element directly into the jQuery object
var ret = jQuery( elem || [] );
// Otherwise, we inject the element directly into the jQuery object ret.context = document;
var ret = jQuery( elem ); ret.selector = selector;
ret.context = document; return ret;
ret.selector = selector;
return ret;
}
selector = [];
} }
// HANDLE: $(expr, [context]) // HANDLE: $(expr, [context])
......
...@@ -53,7 +53,7 @@ test("jQuery()", function() { ...@@ -53,7 +53,7 @@ test("jQuery()", function() {
}); });
test("selector state", function() { test("selector state", function() {
expect(28); expect(30);
var test; var test;
...@@ -72,6 +72,10 @@ test("selector state", function() { ...@@ -72,6 +72,10 @@ test("selector state", function() {
test = jQuery("#main"); test = jQuery("#main");
equals( test.selector, "#main", "#main Selector" ); equals( test.selector, "#main", "#main Selector" );
equals( test.context, document, "#main Context" ); equals( test.context, document, "#main Context" );
test = jQuery("#notfoundnono");
equals( test.selector, "#notfoundnono", "#notfoundnono Selector" );
equals( test.context, document, "#notfoundnono Context" );
test = jQuery("#main", document); test = jQuery("#main", document);
equals( test.selector, "#main", "#main Selector" ); equals( test.selector, "#main", "#main Selector" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment