I’ve a search feature in one of code which ideally performs a search on the list of values (small number).
<li>abc</li>
<li>def</li>
...
I’ve a search button in the bottom, I put a keyup event listener to get instant searches. Now the question is how can I make it navigable.
Ideal scenario search for some text, hit enter and it should open the first element, else you should be able to navigate through.
If I’m not clear above I’m actually asking for a feature very similar to Facebook Chat sidebar search.
For the sake of the OP who has not added jQuery to the list of tags ( I congratulate you ), I’ll add a small navigation plugin in pure JavaScript.
Disclosure – the credit for the actual logic would go to Eric Priestley of Facebook fame as this was lifted from his Javelin JS library.
I’m posting a link to the fiddle here. I also assume from your question that you already have a search solution in place and are simply looking for a navigation solution.
Cross posting from fiddle. I’ve commented a lot in the code, so should be self explanatory. Though if you do have doubts, get in touch.
HTML
Can be anything you desire. For brevity, I’ve added this
The code