I have the list of cars which shows both items 'Sold' and 'new' so I want to hide that car from list which have the label of 'sold' in Danish it is called "solgt" I used the following code with the help of jQuery but it disappear every car item in list including 'ny" as well here is the code
jQuery(function($) {
if ($('.slider-car-item:has(.Solgt)')) {
//get checkbox not checked add class disable
$('.slider-car-item').addClass('.dnone');
} else {
//remove class disabled
$('.slider-car-item').removeClass('.dnone');
}
});
.dnone {
display: none;
}
<div class="slider-car-item">
<div>
<article><span class="Solgt">SOLGT</span></article>
<article><span class="ny">NY</span></article>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Just select those elements which have the target class and find the closest ancestor list item. No need for all the logic.
Don't include dots in addClass(). Also, the second clause is pointless unless you'll ever have .dnone on an item at page load.
Alternatively, don't bother with a hide class. Just use jQuery's hide() method.
jQuery(function($) {
$('.slider-car-item li.dnone').removeClass('dnone');
$('.Solgt').closest('li').addClass('dnone');
});
.dnone {
display: none;
}
<div class="slider-car-item">
<div>
<ul>
<li><span class="Solgt">SOLGT</span></li>
<li><span class="ny">NY</span></li>
<li class="dnone"><span class="ny">NY (originally hidden)</span></li>
</ul>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
write in way, and mostly I use 3.5+ jQuery so don't know if there are any difference but should be something like
$('.slider-car-item').find('.Solgt').fadeOut();
or
$('.slider-car-item').find('.Solgt').hide();
or
$('.slider-car-item').find('.Solgt').slideUp();
or
$('.slider-car-item').find('.Solgt').css('display', 'none');
or $('.slider-car-item').find('.Solgt').addClass('dnone') ;