title: Change contenteditable div HTML and move cursor to end don't works
body: <p>I've a problem with a function. My goal is the change the content of my contenteditable div. This works good but I had the cursor jumpt to start problem. So I found a function on SO to fix this. Sadly, this function don't works like expected and throws an error. Maybe it's because I'm using jQuery all over my project?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>jQuery(document).ready(function ($) {
      let input = $("input");
      setTimeout(function () {
          input.html(input.html() + "and I'm &lt;b&gt;very bold&lt;/b&gt;");
          placeCaretAtEnd(input);
      }, 1000);
  });
  
  
  function placeCaretAtEnd(el) {
      el.focus();
  
      if (typeof window.getSelection !== "undefined" &amp;&amp; typeof document.createRange !== "undefined") {
          let range = document.createRange();
  
          range.selectNodeContents(el);
          range.collapse(false);
  
          let sel = window.getSelection();
  
          sel.removeAllRanges();
          sel.addRange(range);
      } else if (typeof document.body.createTextRange !== "undefined") {
          let textRange = document.body.createTextRange();
  
          textRange.moveToElementText(el);
          textRange.collapse(false);
          textRange.select();
      }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>[contenteditable=true] {
    border: 1px solid #aaaaaa;
    padding: 8px;
    border-radius: 12px;
    margin-bottom: 20px;
    white-space: pre-wrap;
    word-wrap: break-word;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="input" contenteditable="true" spellcheck="true"&gt;I'm a &lt;span&gt;text&lt;/span&gt; &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thanks for helping me!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I want to use jQuery because I've implemented a lot with my input variable introduced with jQuery at the beginning. </p>