How do you make the $(this)
selector focus on current element? In this jsfiddle, I've mounted it only goes in a specified element, so you cant press enter to activate the button you 'are in'. http://jsfiddle.net/mathzarro/gd6Ep/1/
Heres the tricky part: $("button:first").trigger('focus');
Ps. I've said I mounted as an expression! The original coder was Ian, here it is the link.. thanks @Ian! http://jsfiddle.net/Vtn5Y/
The real problem was mentioned by HazMat, you were focusing on the wrong element (always the first button using
$("button:first").trigger('focus');
.Calling
liSelected.trigger('focus');
at the end of your keydown handler and removing the other calls to$("button:first").trigger('focus');
will fix the problem.You also have another problem
Here's a working example
Also, the jsfiddle is great but you should post the code relevant code here too.
Improvement suggestion
The code you posted suffers from brittle queries, internal coupling, that is, it's not very flexible to changing HTML structures. I've re-worked your code so that it's in better shape. Here are the main features
Here's the code