The Range.collapse() method collapses the Range to one of its boundary points.

A collapsed Range is empty, containing no content, specifying a single-point in a DOM tree. To determine if a Range is already collapsed, see the Range.collapsed property.

Syntax

range.collapse(toStart);

Parameters

toStart Optional
A boolean value: true collapses the Range to its start, false to its end. If omitted, it defaults to false .

Example

var range = document.createRange();

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

Specifications

Specification Status Comment
DOM
The definition of 'Range.collapse()' in that specification.
Living Standard The parameter is now optional and default to false.
Document Object Model (DOM) Level 2 Traversal and Range Specification
The definition of 'Range.collapse()' in that specification.
Obsolete Initial specification.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 4IE Full support 9Opera Full support 9Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
toStart parameter optional
Experimental
Chrome Full support YesEdge ? Firefox Full support 25IE No support No
Notes
No support No
Notes
Notes Optional but defaults to true.
Opera Full support 15Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 25Opera Android Full support 15Safari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also

Document Tags and Contributors

Tags: 
Last updated by: fscholz,