add a div.class in a child, only when the parent does not have other div.class
Posted
by
armandfp
on Stack Overflow
See other posts from Stack Overflow
or by armandfp
Published on 2011-11-22T09:44:39Z
Indexed on
2011/11/22
9:50 UTC
Read the original article
Hit count: 526
i have a html code like this:
<div class="someclass">
<div class="childclass"></div>
<div class="checkclass"></div>
</div>
<div class="someclass">
<div class="childclass"></div>
</div>
<div class="someclass">
<div class="childclass"></div>
<div class="checkclass"></div>
</div>
<div class="someclass">
<div class="childclass"></div>
<div class="checkclass"></div>
</div>
<div class="someclass">
<div class="childclass"></div>
</div>
and i need to add a div only on those divs that dont have that "checkclass", so it will like this:
<div class="someclass">
<div class="childclass"></div>
<div class="checkclass"></div>
</div>
<div class="someclass">
<div class="childclass"></div>
<div class="newclass"></div>
</div>
<div class="someclass">
<div class="childclass"></div>
<div class="checkclass"></div>
</div>
<div class="someclass">
<div class="childclass"></div>
<div class="checkclass"></div>
</div>
<div class="someclass">
<div class="childclass"></div>
<div class="newclass"></div>
</div>
i tried with jquery something like:
$('.someclase:not(children(hasClass(checkclass))').append('<div class="newclass"></div>');
$('.someclass:not(:children(.checkclass))').append('<div class="newclass"></div>');
$('.someclass > :not(.checkclass)').append('<div class="newclass"></div>');
but still nothing, any ideas?
© Stack Overflow or respective owner