title: JQuery: adding items to list and keeping count of items
body: <p>I have a list of items(for this I have only included one), and I am trying to add more items to my list.  While I can insert a new item at the end of the list, I can not get the id number to be set, it always comes out as 0.</p>
  
  <pre><code>&lt;script&gt;
      var count = $("#playlist").children().length;
  
      $(document).ready(function(){
        $("button").click(function(){
          $("ul").append(
            $('&lt;li&gt;').attr('id', 'list['+ count +']').append(
              $('&lt;div&gt;').attr('class','item').append(
                $('&lt;fieldset&gt;').append(
                  "&lt;input id='list[i][name]' name='list[i][name]' type='text' class='auto' size='40' value ='NEW "+ count +"'&gt;"
                )
              )
            )
          )
        })
      });
  &lt;/script&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class='holder'&gt;
     &lt;ul id="playlist"&gt;
          &lt;li id='list[1]' &gt;&lt;div class='item'&gt;&lt;fieldset&gt;
              &lt;input id='list[1][name]' name='list[1][name]' type='text' class='auto' size='40' value ='one' /&gt;
          &lt;/fieldset&gt;&lt;/div&gt;&lt;/li&gt;
     &lt;/ul&gt;
     &lt;br&gt;
  &lt;button&gt;Add new list item&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>