mozilla

Revision 14165 of Range

  • Revision slug: DOM/range
  • Revision title: range
  • Revision id: 14165
  • Created:
  • Creator: XiaoWP
  • Is current revision? No
  • Comment /* Gecko Methods */
Tags: 

Revision Content

{{template.DomRef()}}

Introduction

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.

Properties

collapsed
Returns a boolean indicating whether the range's start and end points are at the same position.
commonAncestorContainer
Returns the deepest Node that contains the startContainer and endContainer Nodes.
endContainer
Returns the Node within which the Range ends.
endOffset
Returns a number representing where in the endContainer the Range ends.
startContainer
Returns the Node within which the Range starts.
startOffset
Returns a number representing where in the startContainer the Range starts.

Methods

Positioning Methods

These methods set the start and end points of a range.

setStart
Sets the start position of a Range.
setEnd
Sets the end position of a Range.
setStartBefore
Sets the start position of a Range relative to another Node.
setStartAfter
Sets the start position of a Range relative to another Node.
setEndBefore
Sets the end position of a Range relative to another Node.
setEndAfter
Sets the end position of a Range relative to another Node.
selectNode
Sets the Range to contain the node and its contents.
selectNodeContents
Sets the Range to contain the contents of a Node.
collapse
Collapses the Range to one of its boundary points.

Editing Methods

These methods retrieve Nodes from a range and modify the contents of a range.

cloneContents
Returns a document fragment copying the nodes of a Range.
deleteContents
Removes the contents of a Range from the document.
extractContents
Moves contents of a Range from the document tree into a document fragment
insertNode
Insert a node at the start of a Range.
surroundContents
Moves content of a Range into a new node.

Other Methods

compareBoundaryPoints
Compares the boundary points of two Ranges.
cloneRange
Returns a Range object with boundary points identical to the cloned Range.
detach
Releases Range from use to improve performance.
toString
Returns the text of the Range

Gecko Methods

This section describes Range methods that are particular to Mozilla and not part of the W3C DOM specifications.

compareNode
Returns a constant representing whether the node is before, after, inside, or surrounding the range.
comparePoint
Returns -1, 0, or 1 indicationg whether the point occurs before, inside, or after the range.
createContextualFragment
Returns a document fragment created from a given string of code.
intersectsNode
Returns a boolean indicating whether the given node intersects the range.
isPointInRange
Returns a boolean indicating whether the given point is in the range.

Revision Source

<p>
{{template.DomRef()}}
</p>
<h3 name="Introduction"> Introduction </h3>
<p>The <code>Range</code> object represents a fragment of a document that can contain nodes and parts of text nodes in a given document.
</p><p>A range can be created using the <a href="en/DOM/document.createRange">createRange</a> method of the <a href="en/DOM/document">document</a> object.  Range objects can also be retrieved by using the <a href="en/DOM/Selection/getRangeAt">getRangeAt</a> method of the <a href="en/DOM/Selection">selection</a> object.
</p>
<h3 name="Properties"> Properties </h3>
<dl><dt><a href="en/DOM/range.collapsed">collapsed</a>
</dt><dd>Returns a boolean indicating whether the range's start and end points are at the same position.
</dd><dt><a href="en/DOM/range.commonAncestorContainer">commonAncestorContainer</a>
</dt><dd>Returns the deepest Node that contains the startContainer and endContainer Nodes.
</dd><dt><a href="en/DOM/range.endContainer">endContainer</a>
</dt><dd>Returns the Node within which the Range ends.
</dd><dt><a href="en/DOM/range.endOffset">endOffset</a>
</dt><dd>Returns a number representing where in the endContainer the Range ends.
</dd><dt><a href="en/DOM/range.startContainer">startContainer</a>
</dt><dd>Returns the Node within which the Range starts. 
</dd><dt><a href="en/DOM/range.startOffset">startOffset</a>
</dt><dd>Returns a number representing where in the startContainer the Range starts.
</dd></dl>
<h3 name="Methods"> Methods </h3>
<h4 name="Positioning_Methods"> Positioning Methods </h4>
<p>These methods set the start and end points of a range.
</p>
<dl><dt><a href="en/DOM/range.setStart">setStart</a>
</dt><dd>Sets the start position of a Range.
</dd><dt><a href="en/DOM/range.setEnd">setEnd</a>
</dt><dd>Sets the end position of a Range.
</dd><dt><a href="en/DOM/range.setStartBefore">setStartBefore</a>
</dt><dd>Sets the start position of a Range relative to another Node.
</dd><dt><a href="en/DOM/range.setStartAfter">setStartAfter</a>
</dt><dd>Sets the start position of a Range relative to another Node.
</dd><dt><a href="en/DOM/range.setEndBefore">setEndBefore</a>
</dt><dd>Sets the end position of a Range relative to another Node.
</dd><dt><a href="en/DOM/range.setEndAfter">setEndAfter</a>
</dt><dd>Sets the end position of a Range relative to another Node. 
</dd><dt><a href="en/DOM/range.selectNode">selectNode</a>
</dt><dd>Sets the Range to contain the node and its contents.
</dd><dt><a href="en/DOM/range.selectNodeContents">selectNodeContents</a>
</dt><dd>Sets the Range to contain the contents of a Node.
</dd><dt><a href="en/DOM/range.collapse">collapse</a>
</dt><dd>Collapses the Range to one of its boundary points.
</dd></dl>
<h4 name="Editing_Methods"> Editing Methods </h4>
<p>These methods retrieve Nodes from a range and modify the contents of a range.
</p>
<dl><dt><a href="en/DOM/range.cloneContents">cloneContents</a>
</dt><dd>Returns a document fragment copying the nodes of a Range. 
</dd><dt><a href="en/DOM/range.deleteContents">deleteContents</a>
</dt><dd>Removes the contents of a Range from the document.
</dd><dt><a href="en/DOM/range.extractContents">extractContents</a>
</dt><dd>Moves contents of a Range from the document tree into a document fragment
</dd><dt><a href="en/DOM/range.insertNode">insertNode</a>
</dt><dd>Insert a node at the start of a Range. 
</dd><dt><a href="en/DOM/range.surroundContents">surroundContents</a>
</dt><dd>Moves content of a Range into a new node.
</dd></dl>
<h4 name="Other_Methods"> Other Methods </h4>
<dl><dt><a href="en/DOM/range.compareBoundaryPoints">compareBoundaryPoints</a>
</dt><dd>Compares the boundary points of two Ranges.
</dd><dt><a href="en/DOM/range.cloneRange">cloneRange</a>
</dt><dd>Returns a Range object with boundary points identical to the cloned Range. 
</dd><dt><a href="en/DOM/range.detach">detach</a>
</dt><dd>Releases Range from use to improve performance.
</dd><dt><a href="en/DOM/range.toString">toString</a>
</dt><dd>Returns the text of the Range
</dd></dl>
<h4 name="Gecko_Methods"> Gecko Methods </h4>
<p>This section describes Range methods that are particular to Mozilla and not part of the W3C DOM specifications.
</p>
<dl><dt><a href="en/DOM/range.compareNode">compareNode</a>
</dt><dd>Returns a constant representing whether the node is before, after, inside, or surrounding the range.
</dd><dt><a href="en/DOM/range.comparePoint">comparePoint</a>
</dt><dd>Returns -1, 0, or 1 indicationg whether the point occurs before, inside, or after the range.
</dd><dt><a href="en/DOM/range.createContextualFragment">createContextualFragment</a>
</dt><dd>Returns a document fragment created from a given string of code.
</dd><dt><a href="en/DOM/range.intersectsNode">intersectsNode</a>
</dt><dd>Returns a boolean indicating whether the given node intersects the range.
</dd><dt><a href="en/DOM/range.isPointInRange">isPointInRange</a>
</dt><dd>Returns a boolean indicating whether the given point is in the range.
</dd></dl>
Revert to this revision