title: JavaScript + recursive function returning undefined
body: <p>I have a simple html structure that I need to traverse.  For some reason my recursive function returns 'undefined' on any nested nodes, but not for parent nodes.  Unfortunately this needs to be native js, no jQuery for this one.  Thanks!</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div id="container"&gt;
    &lt;div id="head"&gt; 
      &lt;span id="left"&gt;&lt;&lt;/span&gt; 
      &lt;span id="right"&gt;&gt;&lt;/span&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Script:</strong></p>
  
  <pre><code>var h = hasId(container, 'head');
  var l = hasId(container, 'left');
  var r = hasId(container, 'right');
  
  console.log(h + " : " + r + " : " + l);
  //[object HTMLDivElement] : undefined : undefined
  
  function hasId(ele, id) {
      for (var i = 0; i &lt; ele.childNodes.length; i++) {
          var child = ele.childNodes[i];
          if(child.id == id) return child;
          else hasId(child, id);
      }
  }
  </code></pre>