I created this code in jsfiddle ( http://jsfiddle.net/E7MSN/56/ ) and it works for static lists, but in my situation, I also have a query on the keyup event that retrieves a different ul/li depending on what I type in to the search box.
What seems to happen is that every time I press up or down, the keyup event is fired and a new query is issued to the server (PHP script returns the ul and li). Then, the element with the “selected” class is reset to the first list item, instead of going up and down when I press the arrow keys like in the jsfiddle example.
I’ve tried using .change for the textbox, but that doesn’t seem to work either.
Any ideas?
I used the switch statement and I added a default case to handle it instead of putting it at the top of the function. Problem solved!