/
index.md
56 lines (38 loc) · 1.15 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: "Range: collapse() method"
short-title: collapse()
slug: Web/API/Range/collapse
page-type: web-api-instance-method
browser-compat: api.Range.collapse
---
{{APIRef("DOM")}}
The **`Range.collapse()`** method collapses the
{{domxref("Range")}} to one of its boundary points.
A collapsed {{domxref("Range")}} is empty, containing no content, specifying a
single-point in a DOM tree. To determine if a {{domxref("Range")}} is already collapsed,
see the {{domxref("Range.collapsed")}} property.
## Syntax
```js-nolint
collapse()
collapse(toStart)
```
### Parameters
- `toStart` {{optional_inline}}
- : A boolean value: `true` collapses the {{domxref("Range")}}
to its start, `false` to its end. If omitted, it defaults to
`false` {{experimental_inline}}.
### Return value
None ({{jsxref("undefined")}}).
## Examples
```js
const range = document.createRange();
const referenceNode = document.getElementsByTagName("div").item(0);
range.selectNode(referenceNode);
range.collapse(true);
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [The DOM interfaces index](/en-US/docs/Web/API/Document_Object_Model)