Reputation:
HTML structure looks like this: title > ul > li > a
. After clicking on the anchor tag, I need to .slideToggle()
on the .content
element, which is closest to the .title
.
My current js for it looks like this and it doesn't work. Here's a fiddle
$(function(){
$('.title > ul > li > a').on('click', function(){
$(this).closest('.content').slideToggle();
})
})
Upvotes: 0
Views: 56
Reputation: 15129
How about:
$(this).parents('.title').next('.content').slideToggle();
Upvotes: 0
Reputation: 104775
.content
is not in the same tree as your selector, therefore .closest
wont find it. You need to use a combo of .closest
and .next
$(this).closest('.title').next(".content").slideToggle();
Fiddle: http://jsfiddle.net/ad9bz/5/
Also, be sure to include jQuery in your fiddle next time!
Upvotes: 3