I'm trying to add a class to a child via jquery only if all the children of the parent do not contain the class already. I can't figure out what I'm doing wrong:
<style type="text/css">
.active-tag {
color: red;
}
</style>
<div class="tagcloud">
<a class="all" href="#all">All</a>
<a class="test1" href="#1">1</a>
<a class="test2" href="#1">1</a>
<a class="test3" href="#1">1</a>
</div>
<script>
if (!$('.tagcloud a').hasClass('active-tag')) {
$('.all').addClass('active-tag');
}
</script>
Aucun commentaire:
Enregistrer un commentaire