title: JavaScript ranging gone wrong
body: <p>The following code gives me a really weird error in Firefox:</p>
  
  <blockquote>
    <p>Error: uncaught exception:
    [Exception... "Index or size is
    negative or greater than the allowed
    amount"  code: "1" nsresult:
    "0x80530001
    (NS_ERROR_DOM_INDEX_SIZE_ERR)" 
    location: "file:///G:/test.html Line:
    13"]</p>
  </blockquote>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;test&lt;/title&gt;
  
     &lt;script&gt;
  function xxx() {
  
     var myList = document.getElementsByTagName("div");
  
     var range = document.createRange();
     var start = myList[0];
     var end = myList[0];
     range.setStart(start, 1); // Edit: this is (presumably) line 13
     range.setEnd(end, 3); 
  
     window.getSelection().addRange(range);
  }
     &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body onload="xxx();"&gt;
  
     &lt;div&gt;abcddasdsadasda&lt;/div&gt;
     &lt;div&gt;2312321&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Thank you.</p>