def _insert_element_before(self, node: Node, ref_node: Node) -> Node: if node.parentNode: node.parentNode.removeChild(node) self._children.insert(self.index(ref_node), node) node._parent = self return node
def _remove_child(self, node: Node) -> Node: if node not in self._children: raise ValueError('node to be removed is not a child of this node.') self._children.remove(node) node._parent = None return node
def _append_element(self, node: Node) -> Node: if node.parentNode: node.parentNode.removeChild(node) self._children.append(node) node._parent = self return node