You have to call insertBefore
on the parent element of the element you’re inserting before. document.body
is not the parent, it’s far up in the DOM hierarchy.
And to insert after a DIV, you have to insert before its next sibling.
var parentDiv = document.getElementById("remoteVideos");
parentDiv.insertBefore(newVideo, originalDiv.nextSibling);
See the examples in MDN