title: setStart and setEnd throwing error when trying to programmatically select text in UIWebView
body: <p>Here is some HTML that I am working with in my UIWebView:</p>
  
  <pre><code>&lt;div id = "1"&gt;
      &lt;span style = "background-color:red"&gt;
           &lt;a href = "10&amp;20"&gt;
                This is a link
           &lt;/a&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Once the link is tapped, I want to programmatically select the link text in the UIWebView (so "This is a link" would now be highlighted with the blue iOS text selection tool). This is why I am sending some range information in the href of the a tag. This is the call I am using to try and make this programmatic selection:</p>
  
  <pre><code>//set content editable true
  [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"selectElementContentsInRange(document.getElementById('1'), 10, 20)"]];
  </code></pre>
  
  <p>And this is the javascript function:</p>
  
  <pre><code>function selectElementContentsInRange(el, first, second) {
      var range = document.createRange();
      alert("Makes it here");
      range.setStart(el.firstChild, first);
      alert("Doesn't make it here");
      range.setEnd(el.firstChild, second);
  
      var sel = window.getSelection();
      sel.removeAllRanges();
      sel.addRange(range);
  }
  </code></pre>
  
  <p>And as you can see with the alerts, it doesn't make it past the <code>range.setStart()</code> call without throwing an error. The Safari javascript debugger is giving me this error: </p>
  
  <pre><code>IndexSizeError: DOM Exception 1: Index or size was negative, or greater than the allowed value.
  </code></pre>
  
  <p>I have tried so many different things, and nothing is working. I am completely at my wits end and would really appreciate some insight into how to do this. I am beginning to doubt that it is even possible to programmatically select text in UIWebView. Am I wrong? Has anyone done this?</p>