title: Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node
body: <p>I am having an issue with JavaScript. I'm getting this error message:</p>
  <blockquote>
  <p>Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.</p>
  </blockquote>
  <p>Javascript:</p>
  <pre><code>var vidCounter = 0;
  vidCounter++;
  
  var originalDiv;
  var newVideo = document.createElement(&quot;video&quot;);
  
  newVideo.setAttribute(&quot;name&quot;, vidCounter);
  newVideo.setAttribute(&quot;autoplay&quot;, &quot;true&quot;);
  originalDiv = document.getElementById(&quot;othersarea&quot;);
  document.body.insertBefore(newVideo, originalDiv); 
  </code></pre>
  <p>It is trying to add a <code>&lt;video&gt;</code> tag below a div called <code>othersarea</code>.</p>
  <pre><code>&lt;div id=&quot;remoteVideos&quot;&gt;
    &lt;div class=&quot;title&quot;&gt;
      &lt;h2&gt;Others&lt;/h2&gt;
    &lt;/div&gt;
    &lt;div id=&quot;othersarea&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>How do I fix this?</p>
  <p>I also want to run <code>attachMediaStream([VIDEO TAG HERE HOW?], event.stream);</code> on my new video tag.</p>