Makes the given element the immediate successor of this one. The two elements will have the same parent, and the given element will be immediately after this one.
(self, successor)
| 385 | parent.insert(index, predecessor) |
| 386 | |
| 387 | def insert_after(self, successor): |
| 388 | """Makes the given element the immediate successor of this one. |
| 389 | |
| 390 | The two elements will have the same parent, and the given element |
| 391 | will be immediately after this one. |
| 392 | """ |
| 393 | if self is successor: |
| 394 | raise ValueError("Can't insert an element after itself.") |
| 395 | parent = self.parent |
| 396 | if parent is None: |
| 397 | raise ValueError( |
| 398 | "Element has no parent, so 'after' has no meaning.") |
| 399 | # Extract first so that the index won't be screwed up if they |
| 400 | # are siblings. |
| 401 | if isinstance(successor, PageElement): |
| 402 | successor.extract() |
| 403 | index = parent.index(self) |
| 404 | parent.insert(index+1, successor) |
| 405 | |
| 406 | def find_next(self, name=None, attrs={}, text=None, **kwargs): |
| 407 | """Returns the first item that matches the given criteria and |