XML DOM surroundContents() Method
Definition and Usage
The surroundContents() method uses the specified node to enclose the content of the range.
Syntax:
surroundContents(newParent)
Parameter
Parameter | Description |
---|---|
newParent | The node that will become the new parent node of the current range content. |
Throw
This method will throw an exception with the following code in the following cases: DOMException exceptionOr RangeException exception:
DOMException.HIERARCHY_REQUEST_ERR
The inclusive node of the starting point of the current range cannot have child nodes, cannot have newParent The child node of the type, or newParent Is the ancestor node of the inclusive node.
DOMException.NO_MODIFICATION_ALLOWED_ERR
The ancestor node of the current range's boundary points is read-only and insertion operations are not allowed.
DOMException.WRONG_DOCUMENT_ERR
newParent and its range is created with a different Document object.
RangeException.BAD_BOUNDARYPOINTS_ERR
The current range partially selects a node (other than a Text node), so it cannot enclose this area of the document.
RangeException.INVALID_NODE_TYPE_ERR
newParent is a Document, DocumentFragment, DocumentType, Attr, Entity, or Notation node.
Description
This method will redefine the parent node of the current range to newParent, and then newParent inserted at the beginning position of the document range in the document. For example, to put a section of the document into a <div> or <span> element, you can use this method.
If newParent If it is already part of the document, it will first be removed from the document, and its child nodes will also be discarded. When this method returns, the range will be newParent The position before is the start point,newParent The position after is the end point.