title: Is there a simple way to prevent the cursor from moving in a div contenteditable at all, even if JavaScript is used to add text?
body: <p>I had the following code:</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>document.getElementById("myDiv").addEventListener("keydown", function (e){
    if (e.keyCode == 8) {
      this.innerHTML += "&amp;#10240;".repeat(4);
      e.preventDefault();
    }
    //moves cursor
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="myDiv" contenteditable="true"&gt;Enter text.&lt;/div&gt;</code></pre>
  </div>
  </div>
  
  Iv'e seen similar questions, but the answers that Iv'e seen are insufficient for a div contenteditable, and many of them don't work at all.<br>
  how do I make sure that the cursor doesn't get moved automatically?</p>