selection

  • 리비전 슬러그: DOM/selection
  • 리비전 제목: selection
  • 리비전 아이디: 183500
  • 제작일시:
  • 만든이: 권지웅
  • 현재 리비전인가요?
  • 댓글 New page: <breadcrumbs></breadcrumbs> {{DomRef}} == Summary == The class of the object returned by <code>[[DOM:window.getSelection | window.getSelection()]]</code> and other methods. == Descriptio...

리비전 내용

{{ DomRef() }}

Summary

The class of the object returned by window.getSelection() and other methods.

Description

A selection object represents the ranges that the user has selected. Typically, it holds only one range, accessed as follows:

range = sel.getRangeAt(0);

Calling the toString() method returns the text contained in the selection, e.g

selObj = window.getSelection();
window.alert(selObj);

Glossary

Other key terms used in this section.

anchor
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.
focus
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.
range
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.

Properties

anchorNode
Returns the node in which the selection begins.
anchorOffset
Returns the number of characters that the selection's anchor is offset within the anchorNode.
focusNode
Returns the node in which the selection ends.
focusOffset
Returns the number of characters that the selection's focus is offset within the focusNode.
isCollapsed
Returns a boolean indicating whether the selection's start and end points are at the same position.
rangeCount
Returns the number of ranges in the selection.

Methods

getRangeAt
Returns a range object representing one of the ranges currently selected.
collapse
Collapses the current selection to a single point.
extend
Moves the focus of the selection to a specified point.
collapseToStart
Moves the focus of the selection to the same point at the anchor.
collapseToEnd
Moves the anchor of the selection to the same point as the focus. The focus does not move.
selectAllChildren
Adds all the children of the specified node to the selection.
addRange
A range object that will be added to the selection.
removeRange
Removes a range from the selection.
removeAllRanges
Removes all ranges from the selection.
deleteFromDocument
Deletes the selection's content from the document.
selectionLanguageChange
toString
Returns a string currently being represented by the selection object, i.e. the currently selected text.
containsNode
Indicates if a certain node is part of the selection.

See also

window.getSelection, Range

{{ languages( { "en": "en/DOM/Selection", "es": "es/DOM/Selection", "fr": "fr/DOM/selection", "it": "it/DOM/Selection", "pl": "pl/DOM/Selection" } ) }}

리비전 소스

<p>
{{ DomRef() }}
</p>
<h3 id="Summary" name="Summary"> Summary </h3>
<p>The class of the object returned by <code><a href="ko/DOM/window.getSelection"> window.getSelection()</a></code> and other methods.
</p>
<h3 id="Description" name="Description"> Description </h3>
<p>A selection object represents the <a href="ko/DOM/range">ranges</a> that the user has selected. Typically, it holds only one range, accessed as follows:
</p>
<pre class="eval">range = sel.getRangeAt(0);
</pre>
<p>Calling the <code><a href="ko/DOM/Selection/toString">toString()</a></code> method returns the text contained in the selection, e.g
</p>
<pre class="eval">selObj = window.getSelection();
window.alert(selObj);
</pre>
<h3 id="Glossary" name="Glossary"> Glossary </h3>
<p>Other key terms used in this section.
</p>
<dl><dt>anchor
</dt><dd>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.
</dd><dt>focus
</dt><dd>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.
</dd><dt>range
</dt><dd>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 <a href="ko/DOM/range">range</a> object. Range objects can also be created via the DOM and programmatically added or removed from a selection.
</dd></dl>
<h3 id="Properties" name="Properties"> Properties </h3>
<dl><dt><a href="ko/DOM/Selection/anchorNode"> anchorNode</a></dt><dd> Returns the node in which the selection begins.
</dd><dt><a href="ko/DOM/Selection/anchorOffset"> anchorOffset</a></dt><dd> Returns the number of characters that the selection's anchor is offset within the anchorNode.
</dd><dt><a href="ko/DOM/Selection/focusNode"> focusNode</a></dt><dd> Returns the node in which the selection ends.
</dd><dt><a href="ko/DOM/Selection/focusOffset"> focusOffset</a></dt><dd> Returns the number of characters that the selection's focus is offset within the focusNode.
</dd><dt><a href="ko/DOM/Selection/isCollapsed"> isCollapsed</a></dt><dd> Returns a boolean indicating whether the selection's start and end points are at the same position.
</dd><dt><a href="ko/DOM/Selection/rangeCount"> rangeCount</a></dt><dd> Returns the number of ranges in the selection.
</dd></dl>
<h3 id="Methods" name="Methods"> Methods </h3>
<dl><dt><a href="ko/DOM/Selection/getRangeAt"> getRangeAt</a></dt><dd> Returns a range object representing one of the ranges currently selected.
</dd><dt><a href="ko/DOM/Selection/collapse"> collapse</a></dt><dd> Collapses the current selection to a single point.
</dd><dt><a href="ko/DOM/Selection/extend"> extend</a></dt><dd> Moves the focus of the selection to a specified point.
</dd><dt><a href="ko/DOM/Selection/collapseToStart"> collapseToStart</a></dt><dd> Moves the focus of the selection to the same point at the anchor.
</dd><dt><a href="ko/DOM/Selection/collapseToEnd"> collapseToEnd</a></dt><dd> Moves the anchor of the selection to the same point as the focus. The focus does not move.
</dd><dt><a href="ko/DOM/Selection/selectAllChildren"> selectAllChildren</a></dt><dd> Adds all the children of the specified node to the selection.
</dd><dt><a href="ko/DOM/Selection/addRange"> addRange</a></dt><dd> A range object that will be added to the selection.
</dd><dt><a href="ko/DOM/Selection/removeRange"> removeRange</a></dt><dd> Removes a range from the selection.
</dd><dt><a href="ko/DOM/Selection/removeAllRanges"> removeAllRanges</a></dt><dd> Removes all ranges from the selection.
</dd><dt><a href="ko/DOM/Selection/deleteFromDocument"> deleteFromDocument</a></dt><dd> Deletes the selection's content from the document.
</dd><dt><a href="ko/DOM/Selection/selectionLanguageChange"> selectionLanguageChange</a></dt><dd> </dd><dt><a href="ko/DOM/Selection/toString"> toString</a></dt><dd> Returns a string currently being represented by the selection object, i.e. the currently selected text.
</dd><dt><a href="ko/DOM/Selection/containsNode"> containsNode</a></dt><dd> Indicates if a certain node is part of the selection.
</dd></dl>
<h3 id="See_also" name="See_also"> See also </h3>
<p><a href="ko/DOM/window.getSelection">window.getSelection</a>,
<a href="ko/DOM/range">Range</a>
</p>
<h3 id="External_links" name="External_links"> External links </h3>
<ul><li> <a class="external" href="http://lxr.mozilla.org/mozilla/source/content/base/public/nsISelection.idl">IDL definition in Mozilla cross-reference</a>
</li></ul>
<div class="noinclude">
</div>
{{ languages( { "en": "en/DOM/Selection", "es": "es/DOM/Selection", "fr": "fr/DOM/selection", "it": "it/DOM/Selection", "pl": "pl/DOM/Selection" } ) }}
Revert to this revision