| 218 | previousSibling = _alias("previous_sibling") # BS3 |
| 219 | |
| 220 | def replace_with(self, replace_with): |
| 221 | if not self.parent: |
| 222 | raise ValueError( |
| 223 | "Cannot replace one element with another when the" |
| 224 | "element to be replaced is not part of a tree.") |
| 225 | if replace_with is self: |
| 226 | return |
| 227 | if replace_with is self.parent: |
| 228 | raise ValueError("Cannot replace a Tag with its parent.") |
| 229 | old_parent = self.parent |
| 230 | my_index = self.parent.index(self) |
| 231 | self.extract() |
| 232 | old_parent.insert(my_index, replace_with) |
| 233 | return self |
| 234 | replaceWith = replace_with # BS3 |
| 235 | |
| 236 | def unwrap(self): |