Skip to content

Instantly share code, notes, and snippets.

@hahmed
Created October 6, 2011 13:55
Show Gist options
  • Save hahmed/1267450 to your computer and use it in GitHub Desktop.
Save hahmed/1267450 to your computer and use it in GitHub Desktop.
javascript ignore case filter
// custom css expression for a case-insensitive contains()
$.expr[':'].Contains = function(a, i, m) {
return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase()) >= 0;
};
$(".search-box").keyup(function(e) {
//get current value
var that = $(this).val();
if (that.length > 0) { //something exists
$(".listofitems .item")
.hide(); //hide all those that does not contain the input
$(".listofitems .item:Contains(" + that + ")")
.show(); //show all that contain the input
}
else {
$(".listofitems .item")
.show(); //nothing entered so show all items by default
}
});
@hahmed
Copy link
Author

hahmed commented Oct 6, 2011

$matches = $(list).find('a:Contains(' + filter + ')').parent();
$('li', list).not($matches).slideUp();
$matches.slideDown();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment