JQuery $ (this) .find not working

I make an accordion with a long list of articles.

I have jQuery working when I use the following: only it will move Up / Down every article on the page:

$('article a').click(function() { $('article').find('h3').slideToggle('fast'); }); 

In theory, this should work, but it does nothing:

 $('article a').click(function() { $(this).find('h3').slideToggle('fast'); }); 

Here you can see the demo: http://jsfiddle.net/CfqGG/

Where am I going wrong?

+7
source share
5 answers

In theory, which should not work because in the click event this refers to <a> , not to <article> , because your click event is bound to <a> .

Try the following:

 $('article a').click(function() { $(this).parent().find('h3').slideToggle('fast'); }); 
+13
source
 $(this).siblings('h3').slideToggle('fast'); 

this refers to element a , and find searches for the element in descendants . h3 not a descendant, but a sibling.

+6
source

You need the following:

 $('article a').click(function() { $(this).closest('article').find('h3').slideToggle('fast'); }); 

Check out demo

+2
source

In your code, $('article a') and then $(this) is inside the anchor.

+1
source

Here is the update code, check it, you need to indicate its sibling, greetings

 $(document).ready(function() { //hides articles $('article h3').hide(); //article accordian $('article a').click(function() { $(this).siblings('h3').slideToggle('fast'); }); }); 
0
source