title: How to put a proper jQuery selector under if condition so that it work for all the cases?
body: <p>Using Jquery each function, i am parsing a div data called as <code>myordersdiv</code></p>
  
  <p>As parsing the <code>myordersdiv</code>, i am creating an array and storing data .</p>
  
  <p><strong>The issue i am facing is that</strong> </p>
  
  <p>If the <code>myordersdiv</code> has got one elmenet under it then its working fine and the o/p is </p>
  
  <pre><code>[{"name":"Choclate"}] 
  </code></pre>
  
  <p>But in case if the <code>myordersdiv</code> has got two elmenets under it , then the o/p is </p>
  
  <p><code>[{"name":"ChocolateVanila "}]</code>  (<strong>Its mixing both of them</strong> )</p>
  
  <p>The fiddle for the first case is </p>
  
  <p><a href="http://jsfiddle.net/GStDU/3/" rel="nofollow">http://jsfiddle.net/GStDU/3/</a></p>
  
  <p>The fiddle for the second case is </p>
  
  <p><a href="http://jsfiddle.net/GStDU/5/" rel="nofollow">http://jsfiddle.net/GStDU/5/</a></p>
  
  <p>Right the jQuery selector is</p>
  
  <pre><code>$.each($('#myordersdiv &gt; ul'), function(i, elem) {
          name = $(elem).find("label").text();
          if (name != 'undefined') {
              //Creating product array 
              products.push({
                  'name': name
              });
          }
      });
  </code></pre>
  
  <p>Could anybody please help ??</p>