Question: HTML :

```
<form>
<fieldset>
    <ul>    
        <li class="answerFields">
            <input type="text" value="" />
            <input type="text" value="" />
            <input type="text" value="" />
        </li>
    </ul>
</fieldset>
</form>

```

JQUERY :

```
$('.inputfield input').last().live('focus', function() {

    //this is just an example//
    document.write('a');
    ...
});

```

I have a [fiddle](http://jsfiddle.net/rayd360/n62GN/2).

I want to be able to check if the input that the user focuses is the last input in the `<li>`

constraints: I cannot change the HTML. The number of inputs will also be increasing or decreasing.

Answer: 
this works regardless of how many inputs per li or how many lis you have

```
<script type="text/javascript" src="jquery-1.5.1.js"></script>
<script type="text/javascript">
var hoverIn = function()
{
    $(this).css('background-color', 'red');
}
var hoverOut = function()
{
    $(this).css('background-color', 'white');
}

var init = function()
{
    var liEls = $('.answerFields');
    for( i=0; i < liEls.length; i++)
    {
        $(liEls[i]).children('input:text').last().hover(hoverIn, hoverOut);
    }
}
window.onload = init;
</script>

<form>
<fieldset>
    <ul>    
        <li class="answerFields">
            <input type="text" value=""/>
            <input type="text" value=""/>
            <input type="text" value=""/>
        </li>
        <li class="answerFields">
            <input type="text" value=""/>
            <input type="text" value=""/>
            <input type="text" value=""/>
            <input type="text" value=""/>
        </li>
        <li class="answerFields">
            <input type="text" value=""/>
            <input type="text" value=""/>
        </li>
        <li class="answerFields">
            <input type="text" value=""/>
            <input type="text" value=""/>
            <input type="text" value=""/>
        </li>
    </ul>
</fieldset>
</form>

```
You can do this

```
$('li.answerFields').on('click','input:last', function() {    
     //document.write('a');
     alert('a');
 });​

```

I see in your fiddle you are using an older version of jQuery, in that case you can use delegate like this

```
$('li.answerFields').delegate('input:last','click', function() {    
     //document.write('a');
     alert('a');
 });​

```