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 1828
一生所求
一生所求 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:25

    Try using the parentNode:

    originalDiv.parentNode.insertBefore(newVideo, originalDiv); 
    

    This will insert newVideo directly in front of the originalDiv.

    The reason is that node.insertBefore(newNode, existingNode) uses node as a reference to the element that surrounds the existingNode.

    Ref: http://www.w3schools.com/jsref/met_node_insertbefore.asp

    It's also what Google Analytics does: http://www.stevesouders.com/blog/2010/05/11/appendchild-vs-insertbefore/

提交回复
热议问题