jQuery closest class selector

javascript, jquery

Solution

Try `.next()` instead of `.closest()` that traverses through the ancestors of the DOM element.

Working Demo

Also you should use `$(this)` rather than `$('.Level2')` else it'll select ALL the `.Level2` rather than the clicked one.

You can also go for something like this - `$(this).closest('.wrap').find('.Level3').fadeToggle();`.

Problem

``` <div class="wrap"> <div class="Level2">Click me</div> <div class="Level3">Information</div> </div> <div class="wrap"> <div class="Level2">Click me</div> <div class="Level3">Information</div> </div> <div class="wrap"> <div class="Level2">Click me</div> <div class="Level3">Information</div> </div> <div class="wrap"> <div class="Level2">Click me</div> <div class="Level3">Information</div> </div> ``` jQuery ``` $('.Level2').click(function(){ $('.Level2').closest('.Level3').fadeToggle(); }); ``` I wanted to select the closest level3 to fadeIn and fadeOut, but doesn't work. Is my syntax wrong? online Sample :http://jsfiddle.net/meEUZ/

Original source