how to add an :eq filter counter to an empty unordered list?
<p>I finally figure out how to ask the right question, and that is, how to add an :eq filter counter to an empty unordered list?</p>

<p>For example, the code below does not seem to add li data only when the ul/li is empty.</p>

<pre><code>&lt;button id="go"&gt;Add&lt;/button&gt;&lt;br&gt;
&lt;label&gt;Position to Add: &lt;input id="pos" value="2" type="text" maxlength="1"&lt;/label&gt;    
&lt;br&gt;
&lt;label&gt;Text to Add: &lt;input id="newText" value="New Item" type="text"&gt;&lt;/label&gt;&lt;br&gt;
&lt;br&gt;
&lt;ul id="list"&gt; &lt;/ul&gt;

$("#go").click(function() {
    var item = $("#newText").val();
    var n = parseInt($("#pos").val(), 10);
    $('#list li').eq(n).after('&lt;li&gt;' + item + '&lt;/li&gt;')
});
</code></pre>

<p>If I manually add an item to the list, then the jquery code below works.</p>

<pre><code>&lt;button id="go"&gt;Add&lt;/button&gt;&lt;br&gt;
&lt;label&gt;Position to Add: &lt;input id="pos" value="2" type="text" maxlength="1"&lt;/label&gt;    
&lt;br&gt;
&lt;label&gt;Text to Add: &lt;input id="newText" value="New Item" type="text"&gt;&lt;/label&gt;&lt;br&gt;
&lt;br&gt;
&lt;ul id="list"&gt;&lt;li&gt; test &lt;/li&gt; &lt;/ul&gt;

$("#go").click(function() {
    var item = $("#newText").val();
    var n = parseInt($("#pos").val(), 10);
    $('#list li').eq(n).after('&lt;li&gt;' + item + '&lt;/li&gt;')
});
</code></pre>
