Packagedom.tr.range
Classpublic class Range
InheritanceRange Inheritance Object
Implements RangeView

Introduced in: DOM 2 Core 

The Range object represents a fragment of a document that can contain nodes and parts of text nodes in a given document.

A range can be created using the createRange method of the Document object. Range objects can also be retrieved by using the getRangeAt method of the selection object.

See also

MDC - range
W3C - DOM Level 2 Range: Range


Public Properties
 PropertyDefined By
  DOM 2 TR collapsed : Boolean
[read-only] Returns a boolean of true if the start and end boundary points of the Range are the same point in the DOM, false if not.
Range
  DOM 2 TR commonAncestorContainer : Node
[read-only] The deepest common ancestor container of the Range's two boundary-points.
Range
  DOM 2 TR endContainer : Node
[read-only] Node within which the Range ends
Range
  DOM 2 TR endOffset : Number
[read-only] Offset within the ending node of the Range.
Range
  DOM 2 TR startContainer : Node
[read-only] Node within which the Range begins.
Range
  DOM 2 TR startOffset : Number
[read-only] Offset within the starting node of the Range.
Range
Public Methods
 MethodDefined By
  
Duplicates the contents of a Range.
Range
  
DOM 2 TR cloneRange():Range
Produces a new Range whose boundary-points are equal to the boundary-points of the Range.
Range
  
DOM 2 TR collapse(toStart:Boolean):void
Collapse a Range onto one of its boundary-points
Range
  
DOM 2 TR compareBoundaryPoints(how:Number, sourceRange:Range):Number
Compare the boundary-points of two Ranges in a document.
Range
  
Non-Standard Obsolete compareNode(refNode:Node):Number
Returns a constant (see notes).
Range
  
Non-Standard comparePoint(refNode:Node, offset:Number):Number
If the referenceNode is a Node of type Text, Comment, or CDATASection, then offset is the number of characters from the start of referenceNode.
Range
  
This method takes a string and uses Mozilla's parser to convert it to a DOM tree.
Range
  
DOM 2 TR deleteContents():void
Removes the contents of a Range from the containing document or document fragment without returning a reference to the removed content.
Range
  
DOM 2 TR detach():void
Called to indicate that the Range is no longer in use and that the implementation may relinquish any resources associated with this Range.
Range
  
Moves the contents of a Range from the containing document or document fragment to a new DocumentFragment.
Range
  
Retrieves an object that specifies the bounds of a collection of TextRectangle objects.
Range
  
Retrieves a collection of rectangles that describes the layout of the contents of an object or range within the client.
Range
  
DOM 2 TR insertNode(newNode:Node):void
Inserts a node into the Document or DocumentFragment at the start of the Range.
Range
  
Non-Standard intersectsNode(refNode:Node):Boolean
Returns a boolean indicating whether the given node intersects the range.
Range
  
Non-Standard isPointInRange(refNode:Node, offset:Number):Boolean
Returns true if the point (cursor position) at offset within ReferenceNode is within this range.
Range
  
DOM 2 TR selectNode(refNode:Node):void
Select a node and its contents
Range
  
DOM 2 TR selectNodeContents(refNode:Node):void
Select the contents within a node Note: The parent Node of the start and end of the Range will be the referenceNode.
Range
  
DOM 2 TR setEnd(refNode:Node, offset:Number):void
Sets the attributes describing the end of a Range.
Range
  
DOM 2 TR setEndAfter(refNode:Node):void
Sets the end of a Range to be after a node Note: The parent Node of end of the Range will be the same as that for the referenceNode.
Range
  
DOM 2 TR setEndBefore(refNode:Node):void
Sets the end position to be before a node.
Range
  
DOM 2 TR setStart(refNode:Node, offset:Number):void
Sets the attributes describing the start of the Range.
Range
  
DOM 2 TR setStartAfter(refNode:Node):void
Sets the start position to be after a node
Range
  
DOM 2 TR setStartBefore(refNode:Node):void
Sets the start position to be before a node
Range
  
DOM 2 TR surroundContents(newParent:Node):void
Reparents the contents of the Range to the given node and inserts the node at the position of the start of the Range.
Range
  
DOM 2 TR toString():DOMString
Returns the contents of a Range as a string.
Range
Public Constants
 ConstantDefined By
  DOM 2 TR END_TO_END : Number = 2
[static] Compare end boundary-point of sourceRange to end boundary-point of Range on which compareBoundaryPoints is invoked.
Range
  DOM 2 TR END_TO_START : Number = 3
[static] Compare end boundary-point of sourceRange to start boundary-point of Range on which compareBoundaryPoints is invoked.
Range
  Non-Standard Obsolete NODE_AFTER : Number = 1
[static] Node ends after the Range
Range
  Non-Standard Obsolete NODE_BEFORE : Number = 0
[static] Node starts before the Range
Range
  Non-Standard Obsolete NODE_BEFORE_AND_AFTER : Number = 2
[static] Node starts before and ends after the Range
Range
  Non-Standard Obsolete NODE_INSIDE : Number = 3
[static] Node starts after and ends before the Range, i.e.
Range
  DOM 2 TR START_TO_END : Number = 1
[static] Compare start boundary-point of sourceRange to end boundary-point of Range on which compareBoundaryPoints is invoked.
Range
  DOM 2 TR START_TO_START : Number = 0
[static] Compare start boundary-point of sourceRange to start boundary-point of Range on which compareBoundaryPoints is invoked.
Range
Property Detail
DOM 2 TR collapsedproperty
collapsed:Boolean  [read-only]

Introduced in: DOM 2 Core 

Returns a boolean of true if the start and end boundary points of the Range are the same point in the DOM, false if not.


Implementation
    public function get collapsed():Boolean

Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.setStart(startNode, startOffset); 
         range.setEnd(endNode, endOffset);
         isCollapsed = range.collapsed;
DOM 2 TR commonAncestorContainerproperty 
commonAncestorContainer:Node  [read-only]

Introduced in: DOM 2 Core 

The deepest common ancestor container of the Range's two boundary-points.

Note: Returns the deepest, or further down the document tree, Node that contains both the startContainer and endContainer nodes. Since a Range need not be continuous, and may also partially select Nodes, this is a convenient way to find a Node which encloses a Range.


Implementation
    public function get commonAncestorContainer():Node

Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.setStart(startNode,startOffset);
         range.setEnd(endNode,endOffset);
         rangeAncestor = range.commonAncestorContainer;
DOM 2 TR endContainerproperty 
endContainer:Node  [read-only]

Introduced in: DOM 2 Core 

Node within which the Range ends


Implementation
    public function get endContainer():Node

Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.setStart(startNode,startOffset); 
         range.setEnd(endNode,endOffset);
         endRangeNode = range.endContainer;
DOM 2 TR endOffsetproperty 
endOffset:Number  [read-only]

Introduced in: DOM 2 Core 

Offset within the ending node of the Range.

Note: endOffset has two meanings. If the endContainer is a Node of type Text, Comment, or CDATASection, then the offset is the number of characters from the start of the endContainer to the boundary point of the Range. For other Node types, the endOffset is the number of child nodes between the start of the endContainer and the boundary point of the Range.


Implementation
    public function get endOffset():Number

Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.setStart(startNode,startOffset);
         range.setEnd(endNode,endOffset);
         endRangeOffset = range.endOffset;
DOM 2 TR startContainerproperty 
startContainer:Node  [read-only]

Introduced in: DOM 2 Core 

Node within which the Range begins.


Implementation
    public function get startContainer():Node

Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.setStart(startNode,startOffset);
         range.setEnd(endNode,endOffset);
         startRangeNode = range.startContainer;
DOM 2 TR startOffsetproperty 
startOffset:Number  [read-only]

Introduced in: DOM 2 Core 

Offset within the starting node of the Range.


Implementation
    public function get startOffset():Number

Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.setStart(startNode,startOffset);
         range.setEnd(endNode,endOffset);
         startRangeOffset = range.startOffset;
Method Detail
DOM 2 TR cloneContents()method
public function cloneContents():DocumentFragment

Introduced in: DOM 2 Core 

Duplicates the contents of a Range.

Note: Event Listeners added using DOM Events are not copied during cloning. HTML attribute events are duplicated as they are for the DOM Core cloneNode method. HTML id attributes are also cloned, which can lead to an invalid document through cloning.

Note: Partially selected nodes include the parent tags necessary to make the document fragment valid.

Returns
DocumentFragment — A DocumentFragment that contains content equivalent to this Range.

Throws
DOMException — HIERARCHY_REQUEST_ERR: Raised if a DocumentType node would be extracted into the new DocumentFragment.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         documentFragment = range.cloneContents();
         document.body.appendChild(documentFragment);
DOM 2 TR cloneRange()method 
public function cloneRange():Range

Introduced in: DOM 2 Core 

Produces a new Range whose boundary-points are equal to the boundary-points of the Range.

Note: clone is copied by value, not reference, so a change in either Range does not effect the other.

Returns
Range — The duplicated Range.

Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         clone = range.cloneRange();
DOM 2 TR collapse()method 
public function collapse(toStart:Boolean):void

Introduced in: DOM 2 Core 

Collapse a Range onto one of its boundary-points

Parameters

toStart:Boolean — If TRUE, collapses the Range onto its start; if FALSE, collapses it onto its end.


Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         referenceNode = document.getElementsByTagName("div").item(0);
         range.selectNode(referenceNode);
         range.collapse(true);
DOM 2 TR compareBoundaryPoints()method 
public function compareBoundaryPoints(how:Number, sourceRange:Range):Number

Introduced in: DOM 2 Core 

Compare the boundary-points of two Ranges in a document.

Parameters

how:Number — A code representing the type of comparison, as defined above.
 
sourceRange:Range — The Range on which this current Range is compared to.

Returns
Number — -1, 0 or 1 depending on whether the corresponding boundary-point of the Range is respectively before, equal to, or after the corresponding boundary-point of sourceRange.

Throws
DOMException — WRONG_DOCUMENT_ERR: Raised if the two Ranges are not in the same Document or DocumentFragment.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         var range, sourceRange, compare;
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div")[0]);
         sourceRange = document.createRange();
         sourceRange.selectNode(document.getElementsByTagName("div")[1]);
         compare = range.compareBoundaryPoints(Range.START_TO_END, sourceRange);
Non-Standard Obsolete compareNode()method 
public function compareNode(refNode:Node):Number

Non-standard (Mozilla)

Obsolete since Gecko 1.9

Returns a constant (see notes).

Note: This method is obsolete; you should use the W3C DOM Range methods (see compareBoundaryPoints()).

Parameters

refNode:Node

Returns
Number

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         returnValue = range.compareNode(document.getElementsByTagName("p").item(0));
comparePoint()method 
public function comparePoint(refNode:Node, offset:Number):Number

Non-standard (Mozilla)

If the referenceNode is a Node of type Text, Comment, or CDATASection, then offset is the number of characters from the start of referenceNode. For other Node types, offset is the number of child nodes between the start of the referenceNode.

Parameters

refNode:Node — The Node to compare with the Range.
 
offset:Number — An integer greater than or equal to zero representing the offset inside the referenceNode.

Returns
Number — Returns -1, 0, or 1 depending on whether the referenceNode is before, the same as, or after the range.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         returnValue = range.comparePoint(document.getElementsByTagName("p").item(0),1);
createContextualFragment()method 
public function createContextualFragment(tagString:DOMString):DocumentFragment

Non-standard (Mozilla)

This method takes a string and uses Mozilla's parser to convert it to a DOM tree.

Parameters

tagString:DOMString — Text that contains text and tags to be converted to a document fragment.

Returns
DocumentFragment — Returns a document fragment.

See also


Example
         var tagString = "<div>I am a div node</div>";
         var range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         var documentFragment = range.createContextualFragment(tagString);
         document.body.appendChild(documentFragment);
DOM 2 TR deleteContents()method 
public function deleteContents():void

Introduced in: DOM 2 Core 

Removes the contents of a Range from the containing document or document fragment without returning a reference to the removed content.

Note: Unlike extractContents, this method does not return a documentFragment containing the deleted content.


Throws
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of the Range is read-only or any of the nodes that contain any of the content of the Range are read-only.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         range.deleteContents();
DOM 2 TR detach()method 
public function detach():void

Introduced in: DOM 2 Core 

Called to indicate that the Range is no longer in use and that the implementation may relinquish any resources associated with this Range. Subsequent calls to any methods or attribute getters on this Range will result in a DOMException being thrown with an error code of INVALID_STATE_ERR.


Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         range.detach();
DOM 2 TR extractContents()method 
public function extractContents():DocumentFragment

Introduced in: DOM 2 Core 

Moves the contents of a Range from the containing document or document fragment to a new DocumentFragment.

Note: Event Listeners added using DOM Events are not retained during extraction. HTML attribute events are retained or duplicated as they are for the DOM Core cloneNode method. HTML id attributes are also cloned, which can lead to an invalid document if a partially-selected node is extracted and appened to the document.

Note: Partially selected nodes are cloned to include the parent tags necessary to make the document fragment valid.

Returns
DocumentFragment — A DocumentFragment containing the extracted contents.

Throws
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of the Range is read-only or any of the nodes which contain any of the content of the Range are read-only.
 
DOMException — HIERARCHY_REQUEST_ERR: Raised if a DocumentType node would be extracted into the new DocumentFragment.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         documentFragment = range.extractContents();
         document.body.appendChild(documentFragment);
CSSOM View getBoundingClientRect()method 
public function getBoundingClientRect():TextRectangle

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.1b Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 TR 

Retrieves an object that specifies the bounds of a collection of TextRectangle objects.

Returns
TextRectangle — The returned value is a TextRectangle object which is the union of the rectangles returned by getClientRects() for the element, i.e., the CSS border-boxes associated with the element.

See also

CSSOM View getClientRects()method 
public function getClientRects():TextRectangleList

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.1b Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 TR 

Retrieves a collection of rectangles that describes the layout of the contents of an object or range within the client. Each rectangle describes a single line.

Returns
TextRectangleList

See also

DOM 2 TR insertNode()method 
public function insertNode(newNode:Node):void

Introduced in: DOM 2 Core 

Inserts a node into the Document or DocumentFragment at the start of the Range.

If the container is a Text node, this will be split at the start of the Range (as if the Text node's splitText method was performed at the insertion point) and the insertion will occur between the two resulting Text nodes. Adjacent Text nodes will not be automatically merged. If the node to be inserted is a DocumentFragment node, the children will be inserted rather than the DocumentFragment node itself.

Parameters

newNode:Node — The node to insert at the start of the Range


Throws
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of the start of the Range is read-only.
 
DOMException — WRONG_DOCUMENT_ERR: Raised if newNode and the container of the start of the Range were not created from the same document.
 
DOMException — HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of a type that does not allow children of the type of newNode or if newNode is an ancestor of the container.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.
 
RangeException — INVALID_NODE_TYPE_ERR: Raised if newNode is an Attr, Entity, Notation, or Document node.

See also


Example
         range = document.createRange();
         newNode = document.createElement("p");
         newNode.appendChild(document.createTextNode("New Node Inserted Here"));
         range.selectNode(document.getElementsByTagName("div").item(0));
         range.insertNode(newNode);
intersectsNode()method 
public function intersectsNode(refNode:Node):Boolean

Non-standard (Mozilla)

Returns a boolean indicating whether the given node intersects the range.

Note: This method is obsolete; you should instead use the W3C DOM Range methods (see compareBoundaryPoints()).

Warning: This method has been removed from Gecko 1.9 and will not exist in future versions of Firefox; you should switch to compareBoundaryPoints() as soon as possible.

Parameters

refNode:Node — The Node to compare with the Range.

Returns
Boolean — Returns a boolean indicating whether the given node intersects the range.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         bool = range.intersectsNode(document.getElementsByTagName("p").item(0));
isPointInRange()method 
public function isPointInRange(refNode:Node, offset:Number):Boolean

Non-standard (Mozilla)

Returns true if the point (cursor position) at offset within ReferenceNode is within this range.

Parameters

refNode:Node — The Node to compare with the Range.
 
offset:Number — The offset into Node of the point to compare with the Range.

Returns
Boolean — Returns a boolean indicating whether the given point is in the range.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         bool = range.isPointInRange(document.getElementsByTagName("p").item(0),1);
DOM 2 TR selectNode()method 
public function selectNode(refNode:Node):void

Introduced in: DOM 2 Core 

Select a node and its contents

Parameters

refNode:Node — The node to select.


Throws
RangeException — INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Entity, Notation or DocumentType node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         referenceNode = document.getElementsByTagName("div").item(0);
         range.selectNode(referenceNode);
DOM 2 TR selectNodeContents()method 
public function selectNodeContents(refNode:Node):void

Introduced in: DOM 2 Core 

Select the contents within a node

Note: The parent Node of the start and end of the Range will be the referenceNode. The startOffset is 0, and the endOffset is the number of child Nodes or number of characters contained in the reference node.

Parameters

refNode:Node — Node to select from


Throws
RangeException — INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Entity, Notation or DocumentType node.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         referenceNode = document.getElementsByTagName("div")[0];
         range.selectNodeContents(referenceNode);
DOM 2 TR setEnd()method 
public function setEnd(refNode:Node, offset:Number):void

Introduced in: DOM 2 Core 

Sets the attributes describing the end of a Range.

Parameters

refNode:Node — The refNode value. This parameter must be different from null.
 
offset:Number — The endOffset value.


Throws
RangeException — INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Entity, Notation, or DocumentType node.
 
DOMException — INDEX_SIZE_ERR: Raised if offset is negative or greater than the number of child units in refNode. Child units are 16-bit units if refNode is a type of CharacterData node (e.g., a Text or Comment node) or a ProcessingInstruction node. Child units are Nodes in all other cases.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         endNode = document.getElementsByTagName("p").item(3);
         endOffset = document.getElementsByTagName("p").item(3).childNodes.length;
         range.setEnd(endNode,endOffset);
DOM 2 TR setEndAfter()method 
public function setEndAfter(refNode:Node):void

Introduced in: DOM 2 Core 

Sets the end of a Range to be after a node

Note: The parent Node of end of the Range will be the same as that for the referenceNode.

Parameters

refNode:Node — Range ends after refNode.


Throws
RangeException — INVALID_NODE_TYPE_ERR: Raised if the root container of refNode is not an Attr, Document or DocumentFragment node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         referenceNode = document.getElementsByTagName("div").item(0);
         range.setEndAfter(referenceNode);
DOM 2 TR setEndBefore()method 
public function setEndBefore(refNode:Node):void

Introduced in: DOM 2 Core 

Sets the end position to be before a node.

Parameters

refNode:Node — Range ends before refNode


Throws
RangeException — INVALID_NODE_TYPE_ERR: Raised if the root container of refNode is not an Attr, Document, or DocumentFragment node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         referenceNode = document.getElementsByTagName("div").item(0);
         range.setEndBefore(referenceNode);
DOM 2 TR setStart()method 
public function setStart(refNode:Node, offset:Number):void

Introduced in: DOM 2 Core 

Sets the attributes describing the start of the Range.

Parameters

refNode:Node — The refNode value. This parameter must be different from null.
 
offset:Number — The startOffset value.


Throws
RangeException — INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Entity, Notation, or DocumentType node.
 
DOMException — INDEX_SIZE_ERR: Raised if offset is negative or greater than the number of child units in refNode. Child units are 16-bit units if refNode is a type of CharacterData node (e.g., a Text or Comment node) or a ProcessingInstruction node. Child units are Nodes in all other cases.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         startNode = document.getElementsByTagName("p").item(2);
         startOffset = 0;
         range.setStart(startNode,startOffset);
DOM 2 TR setStartAfter()method 
public function setStartAfter(refNode:Node):void

Introduced in: DOM 2 Core 

Sets the start position to be after a node

Parameters

refNode:Node — Range starts after refNode


Throws
RangeException — INVALID_NODE_TYPE_ERR: Raised if the root container of refNode is not an Attr, Document, or DocumentFragment node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         referenceNode = document.getElementsByTagName("div").item(0);
         range.setStartAfter(referenceNode);
DOM 2 TR setStartBefore()method 
public function setStartBefore(refNode:Node):void

Introduced in: DOM 2 Core 

Sets the start position to be before a node

Parameters

refNode:Node — Range starts before refNode


Throws
RangeException — INVALID_NODE_TYPE_ERR: Raised if the root container of refNode is not an Attr, Document, or DocumentFragment node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         referenceNode = document.getElementsByTagName("div").item(0);
         range.setStartBefore(referenceNode);
DOM 2 TR surroundContents()method 
public function surroundContents(newParent:Node):void

Introduced in: DOM 2 Core 

Reparents the contents of the Range to the given node and inserts the node at the position of the start of the Range.

Note: surroundContents is equivalent to newNode.appendChild(range.extractContents()); range.insertNode(newNode). After surrounding, the boundary points of the range include newNode.

Parameters

newParent:Node — The node to surround the contents with.


Throws
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of either boundary-point of the Range is read-only.
 
DOMException — WRONG_DOCUMENT_ERR: Raised if newParent and the container of the start of the Range were not created from the same document.
 
DOMException — HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of a type that does not allow children of the type of newParent or if newParent is an ancestor of the container or if node would end up with a child node of a type not allowed by the type of node.
 
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.
 
RangeException — BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-text node.
 
RangeException — INVALID_NODE_TYPE_ERR: Raised if node is an Attr, Entity, DocumentType, Notation, Document, or DocumentFragment node.

See also


Example
         var range = document.createRange();
         var newNode = document.createElement("p");
         range.selectNode(document.getElementsByTagName("div").item(0));
         range.surroundContents(newNode);
DOM 2 TR toString()method 
public function toString():DOMString

Introduced in: DOM 2 Core 

Returns the contents of a Range as a string. This string contains only the data characters, not any markup.

Note: Alerting the contents of a Range makes an implicit toString() call, so comparing range and text through an alert dialog is ineffective

Returns
DOMString — The contents of the Range.

Throws
DOMException — INVALID_STATE_ERR: Raised if detach() has already been invoked on this object.

See also


Example
         range = document.createRange();
         range.selectNode(document.getElementsByTagName("div").item(0));
         text = range.toString();
Constant Detail
DOM 2 TR END_TO_ENDConstant
public static const END_TO_END:Number = 2

Introduced in: DOM 2 Core 

Compare end boundary-point of sourceRange to end boundary-point of Range on which compareBoundaryPoints is invoked.

DOM 2 TR END_TO_STARTConstant 
public static const END_TO_START:Number = 3

Introduced in: DOM 2 Core 

Compare end boundary-point of sourceRange to start boundary-point of Range on which compareBoundaryPoints is invoked.

Non-Standard Obsolete NODE_AFTERConstant 
public static const NODE_AFTER:Number = 1

Non-standard (Mozilla)

Obsolete

Node ends after the Range

See also

Non-Standard Obsolete NODE_BEFOREConstant 
public static const NODE_BEFORE:Number = 0

Non-standard (Mozilla)

Obsolete

Node starts before the Range

See also

Non-Standard Obsolete NODE_BEFORE_AND_AFTERConstant 
public static const NODE_BEFORE_AND_AFTER:Number = 2

Non-standard (Mozilla)

Obsolete

Node starts before and ends after the Range

See also

Non-Standard Obsolete NODE_INSIDEConstant 
public static const NODE_INSIDE:Number = 3

Non-standard (Mozilla)

Obsolete since Gecko 1.9

Node starts after and ends before the Range, i.e. the Node is completely selected by the Range.

See also

DOM 2 TR START_TO_ENDConstant 
public static const START_TO_END:Number = 1

Introduced in: DOM 2 Core 

Compare start boundary-point of sourceRange to end boundary-point of Range on which compareBoundaryPoints is invoked.

DOM 2 TR START_TO_STARTConstant 
public static const START_TO_START:Number = 0

Introduced in: DOM 2 Core 

Compare start boundary-point of sourceRange to start boundary-point of Range on which compareBoundaryPoints is invoked.