mozilla

Revision 313661 of Selection.addRange()

  • Revision slug: DOM/Selection/addRange
  • Revision title: addRange
  • Revision id: 313661
  • Created:
  • Creator: msrdjan
  • Is current revision? No
  • Comment

Revision Content

{{ DomRef() }}

Summary

Adds a {{ domxref("Range") }} to a {{ domxref("Selection") }}.

Syntax

sel.addRange(range)

Parameters

range
A {{ domxref("Range") }} object that will be added to the {{ domxref("Selection") }}.

Examples

 /* Select all STRONG elements in an HTML document */
 var strongs = document.getElementsByTagName("strong");
 var s = window.getSelection();
 if(s.rangeCount > 0) s.removeAllRanges();
 for(var i = 0; i < strongs.length; i++) {
  var range = document.createRange();
  range.selectNode(strongs[i]);
  s.addRange(range);
 }

{{ languages( { "es": "es/DOM/Selection/addRange", "it": "it/DOM/Selection/addRange", "pl": "pl/DOM/Selection/addRange" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p>Adds a {{ domxref("Range") }}&nbsp;to a {{ domxref("Selection") }}.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval">
<em>sel</em>.addRange(<em>range</em>)
</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<dl>
  <dt>
    <em><code>range</code></em></dt>
  <dd>
    A {{ domxref("Range") }} object that will be added to the {{ domxref("Selection") }}.</dd>
</dl>
<h3 id="Examples" name="Examples">Examples</h3>
<pre class="eval">
 /* Select all STRONG elements in an HTML document */
 var strongs = document.getElementsByTagName("strong");
 var s = window.getSelection();
 if(s.rangeCount &gt; 0) s.removeAllRanges();
 for(var i = 0; i &lt; strongs.length; i++) {
  var range = document.createRange();
  range.selectNode(strongs[i]);
  s.addRange(range);
 }
</pre>
<p>{{ languages( { "es": "es/DOM/Selection/addRange", "it": "it/DOM/Selection/addRange", "pl": "pl/DOM/Selection/addRange" } ) }}</p>
Revert to this revision