I want to check to see if an element has a descendent with a certain class X. If so, I want to check that element's siblings to see if they have a descendent with a class Y. If so, I would like to add class to that sibling with the descendent with a class Y.
HTML:
<div class="x">
<div>
<p class="y">Y</p>
</div>
</div>
<div class="x">
<div>
<p class="z">Z</p>
</div>
</div>
jQuery:
$('div').each(function(){
if($(this).find('.y')){
$(this).siblings('div').find('.z').closest('div').addClass(abc);
}
});
Here's a fiddle:
http://ift.tt/1JrgAhg
Thanks for any help!
Aucun commentaire:
Enregistrer un commentaire