Search with Jquery does not work in Firefox

Asked

Viewed 140 times

0

I created a code to search for information in a table and the code just doesn’t work in Firefox

The error that appears in firefox is:

Error: Syntax error, unrecognized Expression: Unsupported pseudo: contains-ci jquery.min.js:2:12733

My code:

$(document).ready(function() {
  //Começa a digitar
  $("#buscar").keyup(function() {
    //pega o css da tabela 
    var tabela = $(this).attr('alt');
    if ($(this).val() != "") {
      $("." + tabela + " tbody>tr").hide();
      $("." + tabela + " td:contains-ci('" + $(this).val() + "')").parent("tr").show();
    } else {
      $("." + tabela + " tbody>tr").show();
    }
  });
  $.extend($.expr[":"], {
    "contains-ci": function(elem, i, match, array) {
      return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table class="table tabela" id="tabela">
  <thead>
    <tr>
      <th>Veículo#</th>
      <th>Placa</th>
      <th>Tipo</th>
      <th>Controle</th>
      <th>Terminal</th>
      <th>Rota</th>
      <th>Último Odômetro</th>
      <th>Leitura</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Porsche</td>
      <td>BUD-0001</td>
      <td>100</td>
      <td>K</td>
      <td>0</td>
      <td>0</td>
      <td>18/04/2017</td>
      <td>1100</td>
    </tr>
    <tr>
      <td>Ferrari</td>
      <td>BUD-0002</td>
      <td>100</td>
      <td>K</td>
      <td>0</td>
      <td>0</td>
      <td>19/04/2017</td>
      <td>200</td>
    </tr>
  </tbody>
</table>
<input id="buscar" alt="tabela" type="text" class="form-control" placeholder="Buscar...">

I’ve already broken my head with this. Does anyone know what can be done?

  • 1

    Here it worked in Firefox. Already tried to remove the caracrete - of the selector name?

  • I already did this. I changed the order too, ie I left $.extend($. expr[":"]... before $("#fetch"). keyup(Function() ... and nothing solved

1 answer

0


I decided to do the search differently and solved the problem:

$(document).on('keyup', '#iPesquisa', function(){
    $("#tabela tr").hide();
    $("#tabela td:contains("+$(this).val().toUpperCase()+")").parent().show();
});
// Função para transformar contains em Maiuscula
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
    return function(elem){
        return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
    };
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.