Skip to content

Commit

Permalink
prev() and next() now support an optional selector argument, which fi…
Browse files Browse the repository at this point in the history
…lters the result; fixes madrobby#485
  • Loading branch information
madrobby committed Apr 18, 2012
1 parent 2432a68 commit 30bc3ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/zepto.js
Expand Up @@ -401,8 +401,8 @@ var Zepto = (function() {
toggle: function(setting){
return (setting === undefined ? this.css("display") == "none" : setting) ? this.show() : this.hide()
},
prev: function(){ return $(this.pluck('previousElementSibling')) },
next: function(){ return $(this.pluck('nextElementSibling')) },
prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') },
next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') },
html: function(html){
return html === undefined ?
(this.length > 0 ? this[0].innerHTML : null) :
Expand Down
8 changes: 8 additions & 0 deletions test/zepto.html
Expand Up @@ -593,11 +593,19 @@ <h1>Zepto DOM unit tests</h1>
testNext: function(t){
t.assertEqual('P', $('#some_element').next().get(0).tagName)
t.assertEqual('DIV', $('p').next().get(0).tagName)

t.assertEqual(0, $('span.yay').next('.nay').size())
t.assertEqual(1, $('span.yay').next().size())
t.assertEqual(1, $('span.yay').next().next('.nay').size())
},

testPrev: function(t){
t.assertEqual('H1', $('p').prev().get(0).tagName)
t.assertEqual('DIV', $('ul').prev().get(0).tagName)

t.assertEqual(0, $('span.nay').prev('.yay').size())
t.assertEqual(1, $('span.nay').prev().size())
t.assertEqual(1, $('span.nay').prev().prev('.yay').size())
},

testEach: function(t){
Expand Down

0 comments on commit 30bc3ae

Please sign in to comment.