title: How to get out of Recursive function?
body: <p>I wrote this function to find a particular element in a table :</p>
  
  <pre><code>function LoopThroughChildElements(parantEle,flag) {
      for (var i = 0; i &lt; parantEle.childNodes.length; i++) {
          if (parantEle.childNodes[i].childNodes.length &gt; 0) {
               LoopThroughChildElements(parantEle.childNodes[i]);
          }
          else {
              if (parantEle.childNodes[i].id.indexOf("chkSelect") &gt; 0) {
                   alert("Found");  
                   return parantEle.childNodes[i];
              }
          }
      }
      return null;
  }
  </code></pre>
  
  <p>When executing this:  </p>
  
  <pre><code> var checkBox = LoopThroughChildElements(col);
   alert(checkBox);
  </code></pre>
  
  <p>I get an alert of <code>"Found"</code>, but the result stays null all time ..</p>
  
  <p>Why does this happen? How to break the recursion loop when I get my result?</p>