Reputation: 367
I have a series of ul, by cliking a button I'm trying to slideDown the ones that are parent of the li.newlist element, and slideUp all the others that are not. I manage to slideDown the ones I want, but I'm not sure how to define the second action, since I can't use .not(). It's probably something very easy, thank you.
HTML
<ul>
<li>A</li>
<li class="newlist">B</li>
</ul>
<ul>
<li>C</li>
<li>D</li>
</ul>
<ul>
<li>E</li>
<li>F</li>
</ul>
SCRIPT
$('button').click(function () {
$('li.newlist').parent().slideDown(400);
});
Upvotes: 0
Views: 42
Reputation: 5610
Here's a FIDDLE
$('button').click(function () {
$('ul').has('.newlist').stop().slideDown(400).siblings('ul').stop().slideUp(400);
});
Upvotes: 1
Reputation: 3279
You could add something like this first:
$('ul').each(function() {
if ($(this).children('.newlist').length == 0) {
$(this).slideUp(400);
}
});
This will slide up only the options that do not contain a .newlist
item.
Upvotes: 0