Navigation Menu

Skip to content

Commit

Permalink
Re-worked the logic for where .selector and .context are added for ID…
Browse files Browse the repository at this point in the history
… selectors (especially ones that aren't found). Fixes jQuery bug jquery#3833.
  • Loading branch information
jeresig committed Jan 20, 2009
1 parent 7647ceb commit 28a1f02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 10 additions & 14 deletions src/core.js
Expand Up @@ -47,20 +47,16 @@ jQuery.fn = jQuery.prototype = {
else {
var elem = document.getElementById( match[3] );

// Make sure an element was located
if ( elem ){
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem.id != match[3] )
return jQuery().find( selector );

// Otherwise, we inject the element directly into the jQuery object
var ret = jQuery( elem );
ret.context = document;
ret.selector = selector;
return ret;
}
selector = [];
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem && elem.id != match[3] )
return jQuery().find( selector );

// Otherwise, we inject the element directly into the jQuery object
var ret = jQuery( elem || [] );
ret.context = document;
ret.selector = selector;
return ret;
}

// HANDLE: $(expr, [context])
Expand Down
6 changes: 5 additions & 1 deletion test/unit/core.js
Expand Up @@ -53,7 +53,7 @@ test("jQuery()", function() {
});

test("selector state", function() {
expect(28);
expect(30);

var test;

Expand All @@ -72,6 +72,10 @@ test("selector state", function() {
test = jQuery("#main");
equals( test.selector, "#main", "#main Selector" );
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);
equals( test.selector, "#main", "#main Selector" );
Expand Down

0 comments on commit 28a1f02

Please sign in to comment.