The class of the object returned by
window.getSelection() and other methods.
A selection object represents the ranges that the user has selected. Typically, it holds only one range, accessed as follows:
range = sel.getRangeAt(0);
toString() method returns the text contained in the selection, e.g
selObj = window.getSelection(); window.alert(selObj);
Other key terms used in this section.
- The anchor of a selection is the beginning point of the selection. When making a selection with a mouse, the anchor is where in the document the mouse button is initially pressed. As the user changes the selection using the mouse or the keyboard, the anchor does not move.
- The focus of a selection is the end point of the selection. When making a selection with a mouse, the focus is where in the document the mouse button is released. As the user changes the selection using the mouse or the keyboard, the focus is the end of the selection that moves.
- A range is a contiguous part of a document. A range can contain entire nodes as well as portions of nodes, such as a portion of a text node. A user will normally only select a single range at a time, but it's possible for a user to select multiple ranges (e.g. by using the Control key). A range can be retrieved from a selection as a range object. Range objects can also be created via the DOM and programmatically added or removed from a selection.
- 선택이 시작된 곳의
Node를 리턴한다. 클릭한 적이 없는 iframe과 같이, 한 번도 문서에서 선택을 한적이 없으면,
- Returns the number of characters that the selection's anchor is offset within the anchorNode.
- 선택이 끝난 노드를 리턴한다.
- Returns the number of characters that the selection's focus is offset within the focusNode.
- 선택 영역의 시작점과 끝점이 같은 위치에 있는지를 나타내는 boolean 값을 리턴한다.
- 선택한 범위의 크기를 리턴한다.
- Returns a range object representing one of the ranges currently selected.
- 선택된 영역을 단일 지점으로 축소한다
- 특정 지점으로 선택 영역의 포커스를 옮긴다.
- 선택 영역의 포커스를 앵커와 같은 지점으로 옮긴다.
- Moves the anchor of the selection to the same point as the focus. The focus does not move.
- Adds all the children of the specified node to the selection.
- A range object that will be added to the selection.
- Removes a range from the selection.
- Removes all ranges from the selection.
- Deletes the selection's content from the document.
- Returns a string currently being represented by the selection object, i.e. the currently selected text.
- Indicates if a certain node is part of the selection.