ListFilter creates a fast, case-insensitive text filter against a list of HTML elements on a page. Sometimes you just need a little thing to do a thing, you know?
This simple implementation finds an unordered list of class my-list
, and prepends it with a text input that filters the li
elements in the list.
var filter = ListFilter({
listContainer: 'ul.my-list',
filterItemClass: 'li'
});
Here’s a more likely use, which creates a text input inside an existing page element with ID filter-list-input-container
. That text input filters children of class filter-item
inside a parent of ID filterable-list
. The child elements may be grouped inside blocks of class filter-block
, and if no children inside a block match the text filter, the entire block is hidden as well. You can try it out below.
var filter = ListFilter({
inputContainer: '#filter-list-input-container',
listContainer: '#filterable-list',
filterItemClass: '.filter-item',
filterBlockClass: '.filter-block'
});
When you create a new filter, these arguments are required:
When you create a new filter, these arguments are optional:
listContainer
.input
element.filterItemClass
(so you can include headers or other markup along with groups). You should pass this a jQuery-style class. During filtering, any member of filterBlockClass
with no visible filter items will also be hidden.var filter = ListFilter({
listContainer: '', //required jQuery-style ID or class, or an HTML tag name
filterItemClass: '', //required jQuery-style class or HTML tag name
inputContainer: '', //optional jQuery-style ID
inputPrompt: '', //optional string
inputClass: '', //optional string
filterBlockClass: '' //optional jQuery-style class
});
MIT.