I have text input, and when I focusing on it – first ‘.option’ of ‘#number_list’ become ‘.selected’. I want to create a feature – when Up or Down key on keybord pressed than next or prev element of ‘number_list’ granding ‘selected’ class and current element loosing this class.
<input type="text" name="number" id="number" maxlength="30" />
<div id="number_list">
<div class='option selected'>aaa</div>
<div class='option'>bbb</div>
<div class='option'>ccc</div>
</div>
I was trying to create array of ‘.option’ elements and get current element by index, but I don’t find any way to do this. So how can it be done? Also I’m using jQuery 1.5.1.
How about this quick-and-dirty implementation: http://jsfiddle.net/zerkms/YNyEr/2/