mozilla

Revision 62384 of Selection.addRange()

  • Revision slug: DOM/Selection/addRange
  • Revision title: addRange
  • Revision id: 62384
  • Created:
  • Creator: Ted_Mielczarek
  • Is current revision? No
  • Comment add some var declarations to the example to avoid strict warnings

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 */
 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);
 }

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 <a href="en/DOM/range">range</a> 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 */
 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>
Revert to this revision