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

171
Visualizações
Case insensitive search with jQuery

I've used the script below to search through a table to display the results matching the user input. If you type in a capital 'K' and the desired result starts with a lower 'k', the result simply won't show as it does not match exactly the user input. How do I select the .value() case insensitive?

$("#search_input").keyup(function() {
  var value = this.value;
  $("#table").find(".table_row").each(function(index) {
    if (!index) return;
    var id = $(this).find(".table_cell").first().text();
    $(this).toggle(id.indexOf(value) !== -1);
  });
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Part of a script which you gave, compare strings as is. Its better to lowercase user input and text id of table cell in order to compare both results and then toggle what you need.

$("#content").keyup(function() {
  var value = this.value.toLowerCase();
  $("#table").find(".table_row").each(function(index) {
    if (!index) return;
    var id = $(this).find(".table_cell").first().text();
    if (id.toLowerCase().indexOf(value) !== -1) {
      $(this).toggle();
    }
  });
});

And one more thing to add. Just curious, why are you passing the result of string comparison to a toggle ? Toggle expect two optional parameters: duration and complete callback function. In case if you don't need to speed up or do something afterwards you just toggle it as is.

With no parameters, the .toggle() method simply toggles the visibility of elements

about 4 years ago · Juan Pablo Isaza Relatório

0

It was enough for me to simply use toLowerCase() for both the searchable elements and the user input, to compare the lower case values of both.

$("#search_input").keyup(function() {
  var value = this.value.toLowerCase();
  $("#table").find(".table_row").each(function(index) {
    if (!index) return;
    var id = $(this).find(".column-namelist").first().text();
    $(this).toggle(id.toLowerCase().indexOf(value) !== -1);
  });
});
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