I put together a simple search field to browse the list, but I have nested lists and it is limited to one list of levels - how do you change
I put it in the violin; http://jsfiddle.net/marksweb/4CJMe/
What do I need to do for mine if(filter)to also check nested elements and not hide the child of the nested list, if there is a result?
Demo site; http://dl.dropbox.com/u/3755926/cssTricks/main.html
(function ($) {
jQuery.expr[':'].Contains = function(a,i,m){
return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
};
function searchList(header, list) {
var form = $("<form>").attr({"class":"filterform","action":"#"}),
input = $("<input>").attr({"class":"filterinput","type":"text"});
$(form).append(input).prependTo(header);
$(input)
.change( function () {
var filter = $(this).val();
if(filter) {
$(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
$(list).find("a:Contains(" + filter + ")").parent().slideDown();
} else {
$(list).find("li").slideDown();
}
return false;
})
.keyup( function () {
$(this).change();
});
}
$(function () {
searchList($("#main"), $("#contents-list"));
});
}(jQuery));
source
share