jquery keypress iterate through each loop?

Posted by user239831 on Stack Overflow See other posts from Stack Overflow or by user239831
Published on 2011-01-01T21:38:13Z Indexed on 2011/01/01 23:54 UTC
Read the original article Hit count: 278

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about keyboard