title: Find dynamically added elem.firstChild
body: <p>I've got some code for dynamically added tabs with content. When removing a tab, eventListener launches a callback function which takes an array of tab + content as parameters.</p>
  
  <p><strong>[newTab]</strong> - array of dynamically created tabs</p>
  
  <p><strong>[newContent]</strong> - array of dynamically created divs (tabs content)
  Here's the code for that:</p>
  
  <pre><code>    tabSpan.addEventListener("click", removeTab([newTab, newContent]));
  </code></pre>
  
  <p>The thing is when I remove a tab with class <em>active</em> I need to pass this class to the first tab in array if it exists, if not - do nothing.
  The issue I am trying to solve is that my <strong>removeTab</strong> function doesn't get the first child of <strong>newTab</strong> array.</p>
  
  <pre><code>    //Remove tab
      function removeTab(nodeArr) {
      return function() {
  
  
          nodeArr.forEach(function(el) {
  
             el.parentNode &amp;&amp; el.parentNode.removeChild(el);
  
          });
  
          console.log(tabs.closest("li.item"));
      };
   }
  </code></pre>
  
  <p><strong>console.log</strong> displays <em>null</em></p>
  
  <p>How can I retrieve that <strong>firstChild</strong> in my case to pass class <em>active</em> to it?</p>
  
  <p>HTML (do not pay attention to the <em>defaultTab</em>, it doesn't count as <em>firstChild</em> in this case):</p>
  
  <pre><code>&lt;div class="wrap"&gt;
  
      &lt;ul id="tabs"&gt;
  
          &lt;li id="defaultTab" class="tab default"&gt;
                  &lt;span&gt;+&lt;/span&gt;
          &lt;/li&gt;
  
  
      &lt;/ul&gt;&lt;!--Tabs ul End--&gt;
  
      &lt;div id="defaultDiv" class="content default"&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p><a href="https://jsbin.com/nugilibome/edit?js,output" rel="nofollow">JS Bin DEMO</a></p>