title: Expand document.getSelection() to entire paragraph
body: <p>With IE, this js code only works when the selection has a non-zero length:</p>
  
  <pre><code>document.execCommand("FormatBlock",false,tag);
  </code></pre>
  
  <p>Getting the containing node is trivial:</p>
  
  <pre><code>var node = document.getSelection().anchorNode;
  </code></pre>
  
  <p>but I don't really understand how to set the selection to encompass all the text of this node. </p>
  
  <p>The single biggest source of confusion for me is ranges, selections, the relationship between the two and how you use them together <em>in the context of a contenteditable div</em> which seems to have different rules from input controls. I tried searching for a tutorial but "selection" and "range" are broad terms and I haven't found anything good yet.</p>
  
  <p>I found <a href="http://msdn.microsoft.com/en-us/library/ie/ms536735(v=vs.85).aspx" rel="nofollow">this in msdn</a> but due to my incomprehension of ranges and selections I couldn't see how to apply it. Here's a code snippet and prefatory text from that page.</p>
  
  <blockquote>
    <p>When applied to a TextRange object, the select method causes the
    current object to be highlighted. The following function uses the
    findText method to set the current object to the text in the TextRange
    object. The function assumes an element that contains the text string
    "text here".</p>
  </blockquote>
  
  <pre><code>function TextRangeSelect() {
    var r = document.body.createTextRange();
    r.findText("text here");
    r.select();
  }
  </code></pre>
  
  <p>From that I wrote the following, but it causes the whole document to be selected.</p>
  
  <pre><code>var sel = document.getSelection();
  var r = document.body.createTextRange();
  r.findText(sel.anchorNode);
  r.select();
  </code></pre>