I m trying to insert a node both before and after a existing node. The problem is, it will only insert one of them. Odd. Can anyone explain why?
这里的法典
// create your new node <p>Hi</p>
var newNode = document.createElement("p");
newNode.appendChild(document.createTextNode("Hi"));
// a existing node for reference
var refNode = document.getElementById("xyz");
// insert newNode before refNode
refNode.parentNode.insertBefore(newNode, refNode);
// insert newNode after refNode
refNode.parentNode.insertBefore(newNode, refNode.nextSibling);