OSDN Git Service

Regular updates
[twpd/master.git] / dom-selection.md
index 1fdd5f9..3e05ec4 100644 (file)
@@ -1,50 +1,52 @@
 ---
 title: DOM Selection
 category: JavaScript
+layout: 2017/sheet
+intro: |
+  Quick introduction to the HTML [DOM selection API](https://devdocs.io/dom/selection).
 ---
 
-## Selection
-See <http://devdocs.io/dom/selection>
+## Reference
+{: .-three-column}
+
+### Selection
 
 ```js
-var selection = document.getSelection()
+var sel = document.getSelection()
 ```
 
-## Methods
+See: <https://devdocs.io/dom/selection>
+
+### Methods
 
 ```js
-selection
-  .removeAllRanges()   // deselects
-  .addRange(range)     // sets a selection
-  .removeRange(range)  // remove a range
+sel.removeAllRanges() //  deselects
+sel.addRange(range) //    sets a selection
+sel.removeRange(range) // remove a range
 ```
 
 ```js
-selection
-  .rangeCount          // ranges
-  .getRangeAt(0)       // get the 0th range
+sel.rangeCount
+sel.getRangeAt(0) // get the 0th range
 ```
 
 ### Collapsing
 
 ```js
-selection
-  .collapse(parent, offset)
-  .collapseToEnd()
-  .collapseToStart()
-  .isCollapsed
+sel.collapse(parent, offset)
+sel.collapseToEnd()
+sel.collapseToStart()
+sel.isCollapsed
 ```
 
 ```js
-selection
-  .containsNode(node)
+sel.containsNode(node)
 ```
 
 ### Deleting
 
 ```js
-selection
-  .deleteFromDocument()
+sel.deleteFromDocument()
 ```
 
 ### Events