Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda