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?
jQuery(document).ready(function ($) {
    let input = $("input");
    setTimeout(function () {
        input.html(input.html() + "and I'm <b>very bold</b>");
        placeCaretAtEnd(input);
    }, 1000);
});
function placeCaretAtEnd(el) {
    el.focus();
    if (typeof window.getSelection !== "undefined" && 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();
    }
}[contenteditable=true] {
  border: 1px solid #aaaaaa;
  padding: 8px;
  border-radius: 12px;
  margin-bottom: 20px;
  white-space: pre-wrap;
  word-wrap: break-word;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="input" contenteditable="true" spellcheck="true">I'm a <span>text</span> </div>Thanks for helping me!
Edit
I want to use jQuery because I've implemented a lot with my input variable introduced with jQuery at the beginning.
 
    