Reputation: 1080
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.
Upvotes: 2
Views: 45
Reputation: 24001
$('li').not('.parent').hide();
$('li.parent').on('click', function(){
$('li').not('.parent').not($(this).nextUntil('li.parent')).hide();
$(this).nextUntil('li.parent').slideToggle();
});
Upvotes: 1
Reputation: 241078
You could use the .nextUntil()
method in order to select the li
siblings until the next .parent
:
$('li.parent').on('click', function(){
$(this).nextUntil('.parent').show();
});
Upvotes: 4