title: javascript create div and append it next to a child element without id
body: <p>Using the solution suggested here: <a href="https://stackoverflow.com/a/32135318/10279127">https://stackoverflow.com/a/32135318/10279127</a> i'm trying to create a new div, and append it inside a parent div with id, next to a child <code>&lt;a&gt;</code> html element.</p>
  
  <p>html:</p>
  
  <pre><code>&lt;div id="div0"&gt;
  &lt;a href="#" class="link"&gt;anchor text&lt;/a&gt;
  // I'd like to place the new div here
  &lt;/div&gt;
  </code></pre>
  
  <p>js:</p>
  
  <pre><code>Element.prototype.appendAfter = function(element) {
    element.parentNode.insertBefore(this, element.nextSibling);
  }, false;
  
  var NewElement = document.createElement('div');
  NewElement.id = 'newDivID';
  var tToAfter = $('#div' + index + ' &gt; a'); // this is what i tried but doesn't work
  NewElement.appendAfter(tToAfter);
  </code></pre>
  
  <p>If inside <code>.appendAfter(...)</code> instead of <code>tToAfter</code> i write <code>document.getElementById('randomElementId')</code> it works and appends it, so i think must be pure javascript, is there a way in js to do something like: document.getElementById('div' + index).firstChild to get the <code>&lt;a&gt;</code> ?</p>
  
  <p>Or to make it entirely with jQuery using the insertAfter (<a href="https://stackoverflow.com/a/8707793/10279127">https://stackoverflow.com/a/8707793/10279127</a>) ?</p>