Trying to make this jQuery filter that uses .find case-insensitive.
For example, when the search = \"cat\" (no quotes) it will find \"cat\" but not \"Cat\" or \"CAT\". S
Convert both strings to lowercase, and then do the search:
search = $(this).val().toLowerCase();
$li.text().toLowerCase().search(search);
you want to make case insensitive searches. try using regex search(/string/i)
$("#filter").live("keyup", function (ev) {
var $filter = $(this),
keyCode = ev.keyCode || ev.which,
search;
if (keyCode === 27) { //ESC
$filter.val("");
}
search = $(this).val() ;
// added
var search_regex = new RegExp(search, 'i');
$("#results").find("li").each(function () {
var $li = $(this);
if (search === "") {
$li.show();
} else {
if (_.include(service_names, search)) {
$li.toggle($li.hasClass("items-" + search));
} else {
// changed here
if (search_regex.test($li.text())) {
$li.show();
} else {
$li.hide();
}
}
}
});
});