Permalink
Browse files

Add `fn.eq()` method

Chainable in situations where `$(something.get(n))` won't work.
  • Loading branch information...
sorentwo committed Jan 1, 2011
1 parent d4d51fe commit e40d1b76b138f4994daed3d46a33571fd0309d19
Showing with 14 additions and 0 deletions.
  1. +1 −0 src/zepto.js
  2. +13 −0 test/zepto.html
View
@@ -63,6 +63,7 @@ var Zepto = (function() {
is: function(selector){
return this.length > 0 && $(this.dom[0]).filter(selector).length > 0;
},
+ eq: function(idx){ return $(this.get(idx)) },
first: function(){ return $(this.get(0)) },
last: function(){ return $(this.get(this.length - 1)) },
find: function(selector){
View
@@ -251,6 +251,19 @@ <h1>Zepto DOM unit tests</h1>
t.assertEqual(4, index);
},
+ testEq: function(t){
+ var zepto = $('h1,p'),
+ zepto2 = zepto.eq(0);
+
+ t.assertLength(5, zepto);
+ t.assertLength(1, zepto2);
+
+ t.refuteIdentical(zepto, zepto2);
+ t.assertUndefined(zepto2.tagName);
+
+ t.assertLength(0, $('nonexistent').eq(0));
+ },
+
testFirst: function(t){
var zepto = $('h1,p');
t.assertLength(5, zepto);

0 comments on commit e40d1b7

Please sign in to comment.