title: How do you set a variable to be an empty, but workable Jquery object?
body: <p>Outside of a for I declare a variable using <code>var list;</code>.  I use this variable inside of my for loop like so:</p>
  
  <pre><code>// add the html to the list
  if (list == undefined)
      list = item;
  else
      list.append(item.contents());
  </code></pre>
  
  <p><code>item</code> is a cloned jquery object build from a <code>$('list_template').clone();</code> call (list_template is a div with <code>&lt;li&gt;</code> elements inside).  What I am doing is creating a list, which I will then appendTo() where I need it.  </p>
  
  <p>Right now this code works fine, but it doesn't seem right to me.  Unfortunatly, I cannot seem to figure out how to correctly declare the <code>list</code> variable to be an empty Jquery object.  I have tried both:</p>
  
  <pre><code>var list = $([]);
  var list = $('');
  </code></pre>
  
  <p>Both of those cause the append to not work correctly (or as expected) with list.html() being null.  Is there a way to initialize my variable to an empty jquery object, so all I have to do is <code>list.append(item.contents());</code> without the if/else statements?</p>
  
  <p><hr>
  <b>Edit:</b> Ok to lessen confusion here is the whole javascript function that currently works fine:</p>
  
  <pre><code>        var list;
  
          // Loop through all of the objects
          var objects = data.objects;
          for (x = 0; x &lt; objects.length; x++) {
              // Clone the object list item template
              var item = $("#object_item_list_template").clone();
  
              // Setup the click action and inner text for the link tag in the template
              item.find('a').bind('click', { val: objects[x].Id }, function (e) { ShowObjectDetails(e.data.val); })
                            .html(objects[x].Name);
  
              // add the html to the list
              if (list == undefined)
                  list = item;
              else
                  list.append(item.contents());
          }
          // set the list of the topics to the topic list
          $("#object_list").empty();
          $('&lt;ul&gt;').appendTo("#object_list").append(list.contents());
  </code></pre>
  
  <p>The object list template is as follows:</p>
  
  <pre><code>&lt;div id="object_item_list_template" style="display:none"&gt;
      &lt;li class="object_item"&gt;&lt;a href="#"&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This all works correctly by cloning the list item, setting up the click action, and adding it to the list on the display.  </p>
  
  <p>I am trying to get rid of the if/else statement.  I can't just do list.append() because if list is undefined (or not a Jquery object), it throws an exception.</p>