Can't find the issue: javascript/jQuery
<p>I have the following function that gets called on the KeyDown event of a link.
Basically I'm trying to move down the table (the application calls it a ListBox).  In the first loop what I'm trying to do is see if they use the mouse to click inside the table first and my hope was to find the row value and then manipulate the class (highlight) from there.</p>

<p>Unfortunately right now I'm not even getting that far.  When the screen loads and I press the down button, the current row (0) has it's class changed as well as row (1).  But on the next down button press the tr_lst says it is undefined.  Which then throws the loop off and then I get all sorts of errors.</p>

<p>I tried to implement a <a href="http://jsfiddle.net/pXa4F/" rel="nofollow">jsfiddle</a>, however, I couldn't get it working.  But you can see some of the code I'm trying to implement.</p>

<pre><code>function xKeyDown(event,ListBoxVal){


var tr_lst = $('#' + ListBoxVal).find('tr[class="LUGridRowHighlight"]');
var iCount = 0;

for (iCount = 0; iCount &lt;= $('#' + ListBoxVal + ' tr').length; iCount++){
    if($('#' + ListBoxVal + ' tr:eq('+iCount+')').attr('id') == tr_lst.attr('id')){
        lstRow = iCount;
        break;
    }
}


if (event.keyCode == 40){
//arrow down
    if(parseInt(lstRow) &lt; $('#' + ListBoxVal + ' tr').length)
    {
        if(parseInt(lstRow) == 0){
            document.getElementById(ListBoxVal).focus(); 
            lstRow +=1;

            document.getElementById($('#' + ListBoxVal + ' tr:eq('+parseInt(lstRow)+')').attr('id')).focus();
            $('#' + ListBoxVal + ' tr:eq('+parseInt(lstRow)+')').addClass('LUGridRowHighlight');
            $('#' + ListBoxVal + ' tr:eq('+parseInt(lstRow)+')').prev().removeClass('LUGridRowHighlight') .addClass('LUGridRow');

        }else{
            document.getElementById($('#' + ListBoxVal + ' tr:eq('+parseInt(lstRow)+')').attr('id')).focus();
            $('#' + ListBoxVal + ' tr:eq('+parseInt(lstRow)+')').addClass('LUGridRowHighlight');
            $('#' + ListBoxVal + ' tr:eq('+parseInt(lstRow)+')').prev().removeClass('LUGridRowHighlight') .addClass('LUGridRow');
            lstRow +=1;
        }
    }
...
</code></pre>

<p><strong>Update:</strong></p>

<p>After looking into this further...  It appears that when I click the down arrow more than once the following code is causing an error:</p>

<pre><code>var tr_lst = $('#' + ListBoxVal).find('tr[class="LUGridRowHighlight"]');
</code></pre>

<p>When I try to print this out it is <strong><em>'undefined'</em></strong></p>

<p>I'm wondering since I am manipulating the class via jQuery do I need to add a .live somewhere to the find?  As I believe when elements are manipulated dynamically the .live comes into play.  Any suggestions?</p>
