function replaceWith($content) { $node_index = $this->index(); // Add the new node. $node = $this->createNode($content); $node->changeParent($this->parent, $node_index); // Remove this node. $this->remove(); return $node; }