title: contenteditable selected text save and restore
body: <p>I came across this post that shows 2 functions on how to save and restore selected text from a contenteditable div. I have the below div set as contenteditable and the 2 function from the other post. How to i use these functions to save and restore selected text. </p>
  
  <pre><code>&lt;div style="width:300px;padding:10px;" contenteditable="true"&gt;test test test test&lt;/div&gt;
  
  &lt;script&gt;
  function saveSelection() {
      if (window.getSelection) {
          sel = window.getSelection();
          if (sel.getRangeAt &amp;&amp; sel.rangeCount) {
              return sel.getRangeAt(0);
          }
      } else if (document.selection &amp;&amp; document.selection.createRange) {
          return document.selection.createRange();
      }
      return null;
  }
  
  function restoreSelection(range) {
      if (range) {
          if (window.getSelection) {
              sel = window.getSelection();
              sel.removeAllRanges();
              sel.addRange(range);
          } else if (document.selection &amp;&amp; range.select) {
              range.select();
          }
      }
  }
  &lt;/script&gt;
  </code></pre>