mozilla

Revision 62382 of Selection.addRange()

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

Revision Content

{{template.DomRef()}}

Summary

Adds a range to the selection.

Syntax

sel.addRange(range)

Parameters

range
A range object that will be added to the selection.

Examples

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

Revision Source

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