4 ms·
If anyone tests this with a long list (like, thousand+ names, every US county, every weather station, etc) please post some stats on how well it scales.
by Sukotto 17y ago
If anyone tests this with a long list (like, thousand+ names, every US county, every weather station, etc) please post some stats on how well it scales.
- kilian 17y agoThere 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