jQuery get the last element after editing the DOM
<p>I have the following function that adds inputs to the DOM and gives them sequential ids based on the last one on the screen. However it only seems to count the actual last one from the pre-edited DOM... so for example if I have 5 inputs by default it will give all the news ones and id of 6 rather than 6,7,8 etc. How do I count the added ones?</p>

<pre><code>addInput: function () {

    // Get the last input num
    $lastNum = $('.inputs input:last-child').length;

    // Num is last input plus 1
    $num = $lastNum + 1;

    // Input HTML
    $input = '&lt;input type="text" name="iam' + $num + '" id="iam' + $num +'" /&gt;';

    // Only allow 10 inputs to be added
    if ( $('.inputs input').length &gt; 9 ) {
        alert('You can only have a maximum of 10');
        return false;
    }

    // Append the input to the inputs list
    $('.inputs').append($input);

},
</code></pre>
