I need check every .archive_blocks for containing .archive_blocks_fa_active.
If is it true, apply css to .archive_blocks_sa.
<div class="archive_blocks">
<a href="#" class="archive_blocks_fa_active">
<img width="142" height="142" src="#">
</a>
<div class="archive_blocks_name">
<a href="#" class="archive_blocks_sa">Ilustrations</a>
</div>
</div>
JQUERY:
$('.archive_blocks').each(function(){
if ( $("a.archive_blocks_fa_active").parents(this).length == 1 ) {
alert('OK');
} else {
alert('NO');
}
});
Assuming I’ve understood your question correctly, can’t you just do this and not bother with the
each:This uses a descendant selector which matches any
a.archive_blocks_fa_activeelement that is a descendant of an.archive_blockselement. It then finds the related.archive_blocks_sa(there would be other ways of doing that, perhaps usingparentandnextif you prefer) and then adds the class.