I want to remove the class description when no <img>
tag is found in all the divs with .box1
:
<ul class="radio accomodation-radio">
<li class="homeing-outer0 homeing-outer clearfix active" style="display: block;">
<div class="box1 clearfix">
<div class="description">
<p>Preis pro Person, nur Mehrbettzimmerbelegung. Sie teilen sich Hotelzimmer im Großraum Reykjavik und 2-4-Bett-Zimmer mit bezogenen Betten während der Tour.</p>
</div>
</div>
</li>....
I tried this, but that is not working:
$(".accomodation-radio").find(".box1 img").each( function(){
if ($(this).length === 0){
$(this).find("div").removeClass(".description");
}
});
You can use combination of :not()
and :has()
selector
$(".accomodation-radio .box1:not(:has(img)) div").removeClass("description")
$(".accomodation-radio .box1:not(:has(img)) div").removeClass("description")
.box1 .description{color:green}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="radio accomodation-radio">
<li class="homeing-outer0 homeing-outer clearfix active" style="display: block;">
<div class="box1 clearfix">
<div class="description">
<p>Preis pro Person, nur Mehrbettzimmerbelegung. Sie teilen sich Hotelzimmer im Großraum Reykjavik und 2-4-Bett-Zimmer mit bezogenen Betten während der Tour.</p>
</div>
</div>
</li>
Your .each()
is trying to run on elemnts that don't exist - you need to pass the .find
inside the loop like this:
$(".accomodation-radio").each(function() {
if ($(this).find(".box1 img").length === 0)
{
$(this).find("div").removeClass("description");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With