surroundContents
Summary
Moves the contents of a Range to a new parent node, placing the new parent node at the start position of the Range.
Syntax
var result = range.surroundContents(/* see parameter list */);
Parameters
newNode
- Data-type
 - DOM Node
 
The new node to make the parent.
Return Value
Returns an object of type NumberNumber
Type: HRESULT
This method can return one of these values.
| Return code | Description | 
|---|---|
| S_OK | The operation completed successfully. | 
| HierarchyRequestError | A document type node is included in the Range that is being cloned. | 
| InvalidStateError | detach has been invoked on the object. | 
| NoModificationAllowedError | A boundary point in the Range is read-only. | 
Examples
var range = document.createRange();
var newNode = document.createElement("p");
range.selectNode(document.getElementsByTagName("div").item(0));
range.surroundContents(newNode);
Notes
Remarks
If the newParent already exists in the document, its content is removed.
Syntax
range.surroundContents(newNode);
Standards information
Related specifications
- DOM
 - Living Standard
 
Attributions
Mozilla Developer Network
: [Range.surroundContents Article]Microsoft Developer Network: [surroundContents Method Article]