Reputation: 55273
This is the structure:
I want toggle ul.children
by clicking a.exchand-cat-item
. I tried this:
$('a.expand-cat-item').on('click', function() {
$(this).siblings('ul.children').toggle('slow');
});
But then realized that it doesn't work because ul.children
is one level up in the DOM tree of a.exchand-cat-item
What's the right way of doing this?
Upvotes: 0
Views: 49
Reputation: 32598
Then go up one level and use siblings
:
$(this).parent().siblings('ul.children');
Upvotes: 1
Reputation: 102753
You could use closest
to first climb back up to the div
element:
$(this).closest('div').siblings('ul.children');
Upvotes: 3