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.

collapse

Summary

Collapses (or removes) a range by moving the insertion point to the beginning or end of the current range.

Method of dom/Rangedom/Range

Syntax

var result = range.collapse(/* see parameter list */);

Parameters

toStart

Data-type
Boolean

(Optional)

Specifies one of the following values:

true (Default). Moves the insertion point to the beginning of the range.

false Moves the insertion point to the end of the range.

Return Value

Returns an object of type

Examples

var range = document.createRange();

var referenceNode = document.getElementsByTagName("div").item(0);
range.selectNode(referenceNode);
range.collapse(true);

Notes

The DOM ‘Living Standard’ specification now recommends that the default parameter value be false… To retain interoperability across browsers ALWAYS specify the toStart parameter (true

Syntax

range.collapse(toStart);

Standards information

Related specifications

DOM
Living Standard

Attributions