Range.selectNodeContents

  • Revision slug: DOM/range.selectNodeContents
  • Revision title: range.selectNodeContents
  • Revision id: 62362
  • Created:
  • Creator: SkyLined
  • Is current revision? No
  • Comment 31 words added

Revision Content

{{ DomRef() }}

Summary

Sets the {{ domxref("Range") }} to contain the contents of a {{ domxref("Node") }}.

Syntax

range.selectNodeContents(referenceNode);

Parameters

referenceNode 
The {{ domxref("Node") }} whose contents will be selected within a {{ domxref("Range") }}.

Example

range = document.createRange();
referenceNode = document.getElementsByTagName("div")[0];
range.selectNodeContents(referenceNode);

Notes

The parent {{ domxref("Node") }} of the start and end of the {{ domxref("Range") }} will be the referenceNode. The startOffset is 0, and the endOffset is the number of child Nodes or number of characters contained in the reference node.

Specification

selectNodeContents

Revision Source

<p>{{ DomRef() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p>Sets the {{ domxref("Range") }} to contain the contents of a {{ domxref("Node") }}.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval"><em>range</em>.selectNodeContents(<em>referenceNode</em>);
</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<dl> <dt>referenceNode </dt> <dd>The {{ domxref("Node") }} whose contents will be selected within a {{ domxref("Range") }}.</dd>
</dl>
<h3 id="Example" name="Example">Example</h3>
<pre class="eval">range = document.createRange();
referenceNode = document.getElementsByTagName("div")[0];
range.selectNodeContents(referenceNode);
</pre>
<h3 id="Notes" name="Notes">Notes</h3>
<p>The parent {{ domxref("Node") }} of the start and end of the {{ domxref("Range") }} will be the <code>referenceNode</code>. The <code>startOffset</code> is 0, and the <code>endOffset</code> is the number of child <code>Nodes</code> or number of characters contained in the reference node.</p>
<h3 id="Specification" name="Specification">Specification</h3>
<p><a class="external" href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/ranges.html#Level2-Range-method-selectNodeContents">selectNodeContents</a></p>
Revert to this revision