3 ms·
There are a couple of optimizations. You can cache the list, by instead of doing this: $(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
by kilian 17y ago
There are a couple of optimizations. You can cache the list, by instead of doing this:
$(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
$(list).find("a:Contains(" + filter + ")").parent().slideDown();
you can do this:
$matches = $(list).find('a:Contains(' + filter + ')').parent();
$('li', list).not($matches).slideUp();
$matches.slideDown();
you can get rid of most of the $(), since input, list, etc are jQuery objects already (I left them in because it makes it easier to read and doesn't have too big an impact)
Lastly, you could save all countries in an array, give all list items unique id's corresponding to the array, match on the array and hide/show the id's that way. You forgo all the DOM interaction until the last moment.
It'll be a while before you get there, though :)
- mathias 17y agoYou’re welcome :p