mozilla

Revision 17549 of Selection.modify()

  • Revision slug: DOM/Selection/modify
  • Revision title: modify
  • Revision id: 17549
  • Created:
  • Creator: Jifeon
  • Is current revision? No
  • Comment 1 words added, 1 words removed

Revision Content

{{ DomRef() }}

{{ gecko_minversion_header("2") }}

Summary

Applies a change to the current selection or cursor position, using simple textual commands.

Note: This method is based on the WebKit method of the same name.

Syntax

sel.modify(alter, direction, granularity)

Parameters

alter
The type of change to apply. Specify "move" to move the current cursor position or "extend" to extend the current selection.
direction
The direction in which to adjust the current selection. You can specify "forward" or "backward" to adjust in the appropriate direction based on the language at the selection point. If you want to adjust in a specific direction, you can specify "left" or "right".
granularity
The distance to adjust the current selection or cursor position. You can move by "character", "word", "sentence", "line", "paragraph", "lineboundary", "sentenceboundary", "paragraphboundary", or "documentboundary".
Note: Gecko does not implement "sentence", "paragraph", "sentenceboundary", "paragraphboundary", or "documentboundary".

Example

To extend the current text selection to include the next word:

var selection = window.getSelection();
selection.modify("extend", "forward", "word");

Revision Source

<p>{{ DomRef() }}</p>
<p>{{ gecko_minversion_header("2") }}</p>
<h3 name="Summary">Summary</h3>
<p>Applies a change to the current selection or cursor position, using simple textual commands.</p>
<div class="note"><strong>Note:</strong> This method is based on the WebKit method of the same name.</div>
<h3 name="Syntax">Syntax</h3>
<pre class="eval"><em>sel</em>.modify(<em>alter</em>, <em>direction</em>, <em>granularity</em>)
</pre>
<h3 name="Parameters">Parameters</h3>
<dl> <dt>alter</dt> <dd>The type of change to apply. Specify "move" to move the current cursor position or "extend" to extend the current selection.</dd> <dt>direction</dt> <dd>The direction in which to adjust the current selection. You can specify "forward" or "backward" to adjust in the appropriate direction based on the language at the selection point. If you want to adjust in a specific direction, you can specify "left" or "right".</dd> <dt>granularity</dt> <dd>The distance to adjust the current selection or cursor position. You can move by "character", "word", "sentence", "line", "paragraph", "lineboundary", "sentenceboundary", "paragraphboundary", or "documentboundary".</dd>
</dl>
<div class="note"><strong>Note:</strong> Gecko does <strong>not</strong> implement "sentence", "paragraph", "sentenceboundary", "paragraphboundary", or "documentboundary".</div>
<h3>Example</h3>
<p>To extend the current text selection to include the next word:</p>
<pre>var selection = window.getSelection();
selection.modify("extend", "forward", "word");
</pre>
Revert to this revision