jQuery - Select series of items unless it has a class

I want to select series of list items unless it has a class. I want to then hide and show.

<ul>
  <li class="parent">Parent</li>
  <li>item</li>
  <li>item</li>
  <li class="parent">Parent</li>
  <li>item</li>
  <li>item</li>
  <li class="parent">Parent</li>
  <li>item</li>
  <li>item</li>
</ul>

jQuery

$('li').not('.parent').hide();
$('li.parent').on('click', function(){
  //select every next siblings unless it finds a classname
});

So when parent is clicked i want to show the next two lists.

I know this would be easy with nested lists. But I am do this over a plugin generated code. This is how its structured.

There’s my code.


solution

You could use the .nextUntil() method in order to select the li siblings until the next .parent:

Example Here

$('li.parent').on('click', function(){
  $(this).nextUntil('.parent').show();
});