user1889007
user1889007

Reputation: 319

List filter doesn't work on keyup, ignores some list items

I found this great list filtering jQuery script and implemented to my simple ol li list. When you type something on the search, it searches for the typed letter from the li items and hides the rest of the lis. Works perfect!

But, I implemented the same script to a more complicated list. The only differece is the HTML, I have extra divs inside my li where as the other one doesn't. When I search for something on the new list it doenst work properly. When I delete the search term, it should slideDown all the original li items but it doenst. Can you guys pleasae have a look at the fiddle below and tell me what Im doing wrong?

Working simple list Fiddle Not properly working list Fiddle

I have a feeling its the script below

$(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
$(list).find("a:Contains(" + filter + ")").parent().slideDown();

I tried few different ways, none of them worked.!

Thanks a lot.

Upvotes: 0

Views: 107

Answers (1)

Tommy Bjerregaard
Tommy Bjerregaard

Reputation: 1099

This should work. http://jsfiddle.net/mpt8T/

$(list).find('li').each(function(){
    if ( $(this).text().indexOf(filter) >= 0 )
        $(this).slideDown();
    else
        $(this).slideUp();
});

Upvotes: 1

Related Questions