1st argument) a node to insert 2nd argument) a reference node - this is the node that the new node will be inserted beforeThe trick to using this method is that the OBJECT on which you actually CALL the insertBefore() method is actually the PARENT node of the reference node! INCORRECT:$DOMNode_refNode->insertBefore($DOMNode_newNode, $DOMNode_refNode); CORRECT:$DOMNode_refNode->parentNode->insertBefore($DOMNode_newNode, $DOMNode_refNode);