Skip to content

Instantly share code, notes, and snippets.

@ocombe
Last active December 18, 2015 10:59
Show Gist options
  • Save ocombe/5771999 to your computer and use it in GitHub Desktop.
Save ocombe/5771999 to your computer and use it in GitHub Desktop.
Inline jQuery search filter
$(document).ready(function() {
// let's make a case insensitive contains selector
$.extend($.expr[':'], {
'containsi': function(elem, i, match, array) {
return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
});
//filter results based on query
function filter(list, selector, filter) {
if(filter) {
// hide all and show matching elements
$(list).hide().filter(function(i) {
return $(this).find(selector+":containsi(" + filter + ")").length > 0;
}).show();
} else {
$(list).show(); // show all
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment