CodingHero
CodingHero

Reputation: 683

jquery - closest seems not working

I have code something like that :

<div class="fieldset clearfix">
<h2 class="fieldset_title">Title <i class="indicator glyphicon  pull-right glyphicon-chevron-down"></i></h2>
<div class="fieldsgroup_info"></div>

<div class="fieldsgroup">
....
</div>
</div>

When I do in jquery

$('.fieldset_title').click(function(){
    $( this ).closest( ".fieldsgroup" ).hide();
}); 

Seems not working, do you have an idea why it doesn't work?

Thanks

Upvotes: 1

Views: 73

Answers (1)

gurvinder372
gurvinder372

Reputation: 68393

.fieldsGroup is the sibling of .fieldset_title not its parent, so replace

$( this ).closest( ".fieldsgroup" ).hide();

with siblings

$( this ).siblings( ".fieldsgroup" ).hide();

Or as suggested by A.Wolff in his comment below

$( this ).nextAll(".fieldsgroup").first().hide();

Upvotes: 3

Related Questions