Name
Range.surroundContents( ): surround range contents with the specified node — DOM Level 2 Range
Synopsis
void surroundContents(NodenewParent)
throws RangeException, DOMException;Arguments
-
newParent The node that is to become the new parent of the contents of this range.
Throws
This method throws a DOMException or RangeException with one
of the following code values in
the following circumstances:
-
DOMException.HIERARCHY_REQUEST_ERR The container node of the start of the range does not allow children or does not allow children of the type of
newParent, ornewParentis an ancestor of that container node.-
DOMException.NO_MODIFICATION_ALLOWED_ERR An ancestor of a boundary point of the range is read-only and does not allow insertions.
-
DOMException.WRONG_DOCUMENT_ERR newParentand this range were created using different Document objects.-
RangeException.BAD_BOUNDARYPOINTS_ERR The range partially selects a node (other than a Text node), so the region of the document it represents cannot be surrounded.
-
RangeException.INVALID_NODE_TYPE_ERR newParentis a Document, DocumentFragment, DocumentType, Attr, Entity, or Notation node.
Description
This method reparents the contents of this range to
newParent and then inserts
newParent into the document at the start
position of the range. It is useful to place a region of document
content within a <div> or
<span> element, for
example.
If newParent is already part of the document, it is first removed from the document, and any children it has are discarded. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access