title: get all immediate child elements with a given tag name? Native JS only
body: <p>No JQuery please.</p>
  
  <p>I'm quite surprised not to have found the answer to this. I'll probably be "duped".</p>
  
  <p>The problem is to get only the <strong>immediate</strong> child elements with a given tag name (e.g. DIV), so <code>getElementsByTagName</code> doesn't work: this will return all descendants with that tag name.</p>
  
  <p>There's a nice-looking answer <a href="https://stackoverflow.com/a/23335484/595305">here</a>, using <code>querySelectorAll()</code>:</p>
  
  <pre><code>const childDivs = document.querySelectorAll('#xyz &gt; div');
  </code></pre>
  
  <p>... but what I've done is just create an element (DIV) on the fly and made its <code>innerHTML</code> equal to the content of a <code>fetch</code>'d HTML file. The consequence of this is to make the BODY's child elements become the child elements of the created element.</p>
  
  <p>So it doesn't have an ID or class, and it's not even in the DOM tree. Of course I can iterate ... but who wants to iterate in 2020! Preposterous. So how might I say:</p>
  
  <pre><code>const childDivs = container.querySelectorAll('ME &gt; DIV');
  </code></pre>
  
  <p>...?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Had a go with the <code>filter</code> idea from Barmer: </p>
  
  <pre><code>const childEls = container.children
  function checkDiv( el ){
      return el.tagName === 'DIV'
  }
  const childDivs = childEls.filter( checkDiv )
  </code></pre>
  
  <p>error: "childEls.filter is not a function"</p>
  
  <p>... I think <code>childEls</code> (class <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection" rel="nofollow noreferrer">HTMLCollection</a>) above is one of those "Array-like" objects. So I believe you have to do this:</p>
  
  <pre><code>const childEls = container.children
  const newArr = Array.prototype.slice.call( childEls );
  const childDivs = newArr.filter( function( el ){ return el.tagName === 'DIV' }  )
  </code></pre>
  
  <p>... which works... but is, in truth, iteration. Boo.</p>