-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
55 lines (40 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
---
title: "Selection: type property"
short-title: type
slug: Web/API/Selection/type
page-type: web-api-instance-property
browser-compat: api.Selection.type
---
{{APIRef("DOM")}}
The **`type`** read-only property of the
{{domxref("Selection")}} interface returns a string describing the
type of the current selection.
## Value
A string describing the type of the current selection. Possible
values are:
- `None`
- : No selection has currently been made.
- `Caret`
- : The selection is collapsed (i.e. the caret is placed on some
text, but no range has been selected).
- `Range`
- : A range has been selected.
## Examples
In this example, the event handler will fire each time a new selection is made.
`console.log(selection.type)` will return `Caret` or
`Range` depending on whether the caret is placed at a single point in the
text, or a range has been selected.
```js
let selection;
document.onselectionchange = () => {
console.log("New selection made");
selection = document.getSelection();
console.log(selection.type);
};
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Selection")}}