Get the parent element (node) of current element (node).
(self)
| 307 | |
| 308 | @property |
| 309 | def parent(self) -> typing.Union[Element, None]: |
| 310 | """Get the parent element (node) of current element (node).""" |
| 311 | if not self.tree: |
| 312 | raise RuntimeError( |
| 313 | "Could not get parent since the element has no tree set." |
| 314 | ) |
| 315 | parent_node = util.filter_recurse( |
| 316 | self.tree, lambda n: n.node_id == self.parent_id |
| 317 | ) |
| 318 | if not parent_node: |
| 319 | return None |
| 320 | parent_element = create(parent_node, tab=self._tab, tree=self.tree) |
| 321 | return parent_element |
| 322 | |
| 323 | @property |
| 324 | def children(self) -> typing.Union[typing.List[Element], str]: |