Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Remove items on the basis of a class name on child element

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>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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>

about 4 years ago · Juan Pablo Isaza Report

0

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') ;

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!