3

what is the next best thing to use when you want to select the next li item, but not the one that has someClassName. The not selector returns an empty array!

or is this a case off using filter?

 <ul class="items">
    <li class="first">pickle</li>
    <li class="someClassName">tomato</li>
    <li>chicken</li>
    <li>cocosnut</li>
  </ul>

var current = $('ul.items li.first');
var next =  current.next(':not(li.someClassName)');

thanks, Richard

Jonas
  • 121,568
  • 97
  • 310
  • 388
Richard
  • 4,516
  • 11
  • 60
  • 87

1 Answers1

7

next only selects the next sibling of the selected element. You can use nextAll method:

var next = current.nextAll(':not(.someClassName)').first();

http://jsfiddle.net/P3EpK/

Note that your markup is not valid.

Ram
  • 143,282
  • 16
  • 168
  • 197
  • I try'd it in firebug and it returns undefined? – Richard Oct 18 '12 at 17:07
  • @Richard Yes and you have unclosed `li` tags. – Ram Oct 18 '12 at 17:07
  • @Richard Have you checked the fiddle in my answer? If you haven't fixed your markup it should return undefined. – Ram Oct 18 '12 at 17:08
  • sorry, lost the browsertab, I still get undefined, I don't get that? I will give the link and you can see yourself with firebug console – Richard Oct 18 '12 at 17:16
  • @Richard I can't see undefined value in the console. Can you provide a jsfiddle? – Ram Oct 18 '12 at 17:25
  • but I gave you the whole page..haha..it doesn't matter firebug was working against me for some reason, your code worked when I uploaded it, you can try hitting the upper arrow button, thanks @undefined – Richard Oct 18 '12 at 17:32