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
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();
}
}
}
});
});