jquery keypress iterate through each loop?
- by user239831
hey guys,
probably a simpel question, however couldn't find anything online.
i have a list with search results and i want to be able to navigate through the list with my up and down keys.
if (e.keyCode == 40) { //down
//alert('down');
$('#searchresults ul li').each(function() {
});
}
if (e.keyCode == 38) { //up
//alert('up');
}
if (e.keyCode == 13) { //enter
//alert('enter');
}
the searchresults look like this:
<ul>
<li class="matched"><a href="link1">link1</a></li>
<li class="matched"><a href="link2">link2</a></li>
<li class="matched"><a href="link3">link3</a></li>
</ul>
So basically i just want to be able to navigate through my searchresults with the up and down keys. the selection of the current element should maybe just change the background color and when i press enter the linked and matched element is fired.
any idea how i can iterate through the searchresults?
thank you