Visit Mozilla.org

DOM:Selection:addRange

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Adds a range to the selection.

[edit] Syntax

sel.addRange(range)

[edit] Parameters

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

[edit] 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);
 }