1
$("#input").keyup(function () {
    var userInput = $(this).val();
    $("#list div").map(function (index, value) {
        $(value).toggle($(value).text().toString().indexOf(userInput) >= 0);
    });
});

here is the code

How do I make it case insensitive? is it possible? I tried using css to force lowercase on user input but did not help.

posit labs
  • 8,951
  • 4
  • 36
  • 66
  • possible duplicate of [JavaScript: case-insensitive search](http://stackoverflow.com/questions/177719/javascript-case-insensitive-search) – Wex Apr 02 '15 at 22:20

3 Answers3

1

This should do the trick

var userInputLower = userInput.toLowerCase();
var shouldToggle = $(value).text().toLowerCase().indexOf(userInputLower) >= 0;
$(value).toggle(shouldToggle);
Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
0

Use string.toLowerCase()

"HELLOOOooo".toLowerCase(); // hellooooo
posit labs
  • 8,951
  • 4
  • 36
  • 66
0

The idea behind case insensitive searches it to convert both the source (string to look for) as well as the target (strings that are compared to the source) to lowercase. Then both have the same casing, which makes it case insensitive.
Converting both the source and target strings to uppercase will give the same result, but to lowercase is used most often.

Paul
  • 323
  • 4
  • 5