dom-selection: add

This commit is contained in:
Rico Sta. Cruz 2015-11-25 00:52:37 +11:00
parent 5f68c60374
commit aa49664dba
1 changed files with 54 additions and 0 deletions

54
dom-selection.md Normal file
View File

@ -0,0 +1,54 @@
---
title: DOM Selection
category: JavaScript
---
## Selection
See <http://devdocs.io/dom/selection>
```js
var selection = document.getSelection()
```
## Methods
```js
selection
.removeAllRanges() // deselects
.addRange(range) // sets a selection
.removeRange(range) // remove a range
```
```js
selection
.rangeCount // ranges
.getRangeAt(0) // get the 0th range
```
### Collapsing
```js
selection
.collapse(parent, offset)
.collapseToEnd()
.collapseToStart()
.isCollapsed
```
```js
selection
.containsNode(node)
```
### Deleting
```js
selection
.deleteFromDocument()
```
### Events
```js
document.addEventListener('selectionchange', () => {})
```