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

前端 未结 2 1831
一生所求
一生所求 2021-01-01 08:56

I am having an issue with Javascript. I\'m getting this error message:

Uncaught NotFoundError: Failed to execute \'insertBefore\' on \'Node\': The nod

2条回答
  •  情歌与酒
    2021-01-01 09:47

    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

提交回复
热议问题