Jquery/JS - Arrow & Return Key Tab Index
<p>I have built my own autocomplete/suggestion feature for my search box.</p>

<p>It works fine but I would love to know how I can use keyword arrow keys, to tab through the list of  linked suggestions. I'm thinking to start by adding (tabIndex=1, tabIndex=2, tabIndex=3...) or (rel="1", rel="2", rel"3"...) to my links.</p>

<p>At the moment, the links are simply:</p>

<pre><code>&lt;a onclick="addSuggToTextbox('suggestion1')" tabIndex="1"&gt;Suggestion 1&lt;/a&gt;
&lt;a onclick="addSuggToTextbox('suggestion2')" tabIndex="2"&gt;Suggestion 2&lt;/a&gt;
...
</code></pre>

<p>Well I could probably figure out left and right key navigation, from previous StackOverflow questions... but what confuses me, is allowing my users to click the 'return' key, when they arrow tabbed to the link/suggestion they wanted.</p>

<p>So let's say I've just used the right arrow key to scroll along the list of links, to the one I want. How can using the 'return' key, detect which link is focused and to imitate it's onclick event? On click of the 'return' key, I would obviously have a function that passed the parameterized value to the text box.</p>

<p><strong>Example:</strong></p>

<p>This is what I have managed already:</p>

<pre><code>$(document).keydown(function(e) {
  if (e.keyCode == 13) { $('myLink??????').click(); }
});
</code></pre>

<p>But how does this function know which link has focus? So I can replace <code>myLink????</code> with the identity of the chosen suggestion link.</p>

<p>Any suggestions to get me started (or finished in my case) would be gratefully received.</p>
