0

I'm making a contact list that contains institutions' phones and emails. I put each institution into a div (class="container"). On the top of the page, I put a search input:

<input type="text" id="textFind">

Then I used JQuery to filter the DIVs, according to the input:

//makes contains case insensitive
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
    return function(elem) {
        return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
    };
});

//filters divs
$("#textFind").keyup(function() {
    var stringPesquisa = $(this).val();
    $(".container").hide();
    $('div:contains(' + stringPesquisa + ')').show()
});

It's working fine, BUT:

QUESTION 1: I need it to ignore accents (for example: "gerencia" could return "Gerência", "primaria" could return "primária"). I tried many ways to do that, nothing has worked so far. Any ideas?

QUESTION 2: I'm learning Javascript and JQuery, so even the "case insensitive" function is working properly, I just can't understand the code. Could someone explain it?

Thanks in advance! :-)

Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
Deniz
  • 42
  • 3
  • 1
    Does this answer your question? [Remove accents/diacritics in a string in JavaScript](https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript) – Jeremy Thille May 26 '20 at 15:05
  • Not actually, sorry, it's quite confusing for me! I tried to use: $(".container").normalize("NFD").replace(/[\u0300-\u036f]/g, ""); But it didn't work. – Deniz May 26 '20 at 15:40
  • 1
    What do you mean "it didn't work"? What exactly did you try? What result did you get? Any errors in the console? – Jeremy Thille May 26 '20 at 16:35
  • Also, really, I'm not sure what the `makes contains case insensitive` function does o_o – Jeremy Thille May 26 '20 at 16:41

0 Answers0