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

159
Visualizações
style="display:none" is not working. Jquery toggle()

I am trying to filter a div, and it is giving style="sidplay:none" to all elements which are not in search result and it is working fine, but the attribute is not hiding the element!

Image here (direct image not available for me)

my code

WikiOption.Elements.searchInput.on("input", (thisx)=> {
    
    var val = $(thisx.target).val();
    $(".toc-wrap h3").each(function () {
        $(this).toggle($(this).text().toLowerCase().includes(val));
    });
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

.toggle() isn't the right method to use in your case. If the next input event fires and a <h3> matches again, then it would change back to it's former state. Use if/else statements and .show() and .hide() methods.

Also, input event doesn't trigger if you Backspace and leave the <input> empty, so a keyup event handler is added.

$('.search').on('input', function(e) {
  const txt = $(e.target).val().toLowerCase();
  $('.toc-wrap h3').each(function() {
    if ($(this).text().toLowerCase().includes(txt)) {
      $(this).show();
    } else {
      $(this).hide();
    }
  });
});

$('.search').on('keyup', function(e) {
  if (e.keyCode === 8 && $(this).val() === '') {
    $('.toc-wrap h3').hide();
  }
});
h3 {
  display: none
}
<input class='search' type='search'>
<article class='toc-wrap'>
  <h3>ABCDEFGHIJ</h3>
  <h3>klmnopqrst</h3>
  <h3>uvwxyz</h3>
  <h3>aAbBcC</h3>
</article>

<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
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