Skip to content

Commit

Permalink
Selector state wasn't being passed along on a cloned jQuery object.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Jan 8, 2009
1 parent 49d0d5b commit c6f189a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/core.js
Expand Up @@ -73,6 +73,12 @@ jQuery.fn = jQuery.prototype = {
} else if ( jQuery.isFunction( selector ) )
return jQuery( document ).ready( selector );

// Make sure that old selector state is passed along
if ( selector.selector && selector.context ) {
this.selector = selector.selector;
this.context = selector.context;
}

return this.setArray(jQuery.makeArray(selector));
},

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

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

var test;

Expand All @@ -80,6 +80,11 @@ test("selector state", function() {
test = jQuery("#main", document.body);
equals( test.selector, "#main", "#main Selector" );
equals( test.context, document.body, "#main Context" );

// Test cloning
test = jQuery(test);
equals( test.selector, "#main", "#main Selector" );
equals( test.context, document.body, "#main Context" );

test = jQuery(document.body).find("#main");
equals( test.selector, "#main", "#main find Selector" );
Expand Down

0 comments on commit c6f189a

Please sign in to comment.