Skip to content

Commit

Permalink
Add support for .get(-Number) Closes #4188
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Jul 16, 2009
1 parent e124fec commit e532dfe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core.js
Expand Up @@ -130,10 +130,10 @@ jQuery.fn = jQuery.prototype = {
return num == null ? return num == null ?


// Return a 'clean' array // Return a 'clean' array
Array.prototype.slice.call( this ) : this.toArray() :


// Return just the object // Return just the object
this[ num ]; ( num < 0 ? this.toArray.call(this, num)[0] : this[ num ] );
}, },


// Take an array of elements and push it onto the stack // Take an array of elements and push it onto the stack
Expand Down
7 changes: 7 additions & 0 deletions test/unit/core.js
Expand Up @@ -340,6 +340,13 @@ test("get(Number)", function() {
equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" ); equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
}); });


test("get(-Number)",function() {
expect(1);
equals( jQuery("p").get(-1),
document.getElementById("first"),
"Get a single element with negative index" )
})

test("add(String|Element|Array|undefined)", function() { test("add(String|Element|Array|undefined)", function() {
expect(12); expect(12);
isSet( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); isSet( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
Expand Down

0 comments on commit e532dfe

Please sign in to comment.