collapse
Summary
Collapses (or removes) a range by moving the insertion point to the beginning or end of the current 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
Mozilla Developer Network : [Range.collapse Article]
Microsoft Developer Network: [collapse Method Article]