Using JavaScript insertBefore() to insert before a TextNode?

后端 未结 2 715
我在风中等你
我在风中等你 2020-12-09 11:27

I have HTML like the following:



Some
相关标签:
2条回答
  • 2020-12-09 11:57

    No, insertBefore will work fine with a text node as the node to be inserted before. The problem is that the node you're trying to insert before is not a child of the node you're inserting into. You need to remove the .parentNode bit:

    newParent.insertBefore(moveable, newParent.firstChild); 
    
    0 讨论(0)
  • 2020-12-09 12:05

    You need to remove the ".parentNode" from your insert statement. A text node is still a node and can be referenced like every other node.

    0 讨论(0)
提交回复
热议问题