This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

getRangeAt

Summary

Returns a specified Range from a selection. The Range is specified by an index and cannot be greater than the number that is returned by rangeCount.

Method of dom/Selectiondom/Selection

Syntax

var range = selObj.getRangeAt(/* see parameter list */);

Parameters

index

Data-type
Number

The zero-based index of the range to return. A negative number or a number greater than or equal to rangeCount will result in an error.

Return Value

Returns an object of type RangeRange

The range object that will be returned.

Examples

var ranges = [];

var selObj = window.getSelection();

for(var i = 0; i < selObj.rangeCount; i++) {
 ranges[i] = selObj.getRangeAt(i);
}
/* Each item in the ranges array is now
 * a range object representing one of the
 * ranges in the current selection */

Notes

Remarks

Currently only Gecko supports multiple or disjointed selections.

Syntax

Standards information

Attributions