title: Simulate backspace button JS
body: <p>I want to create a custom backspace button with the same logic as "backspace" button on a keyboard. I use the following code: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function backSpace()
  {
      var e = jQuery.Event("keyup");
      e.which = 8; // # Some key code value
      e.keyCode = 8;
      $("mainDiv").trigger(e);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;link rel="stylesheet" href="styles.css" type="text/css" media="screen" /&gt;
          &lt;script src="formulas.js"&gt;&lt;/script&gt;
          &lt;script src="http://code.jquery.com/jquery-1.11.3.js"&gt;&lt;/script&gt;
          &lt;meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=no"/&gt;
      &lt;/head&gt;
  
      &lt;button onclick="backSpace()"&gt;backSpace&lt;/button&gt;
      &lt;body id="main" spellcheck="false"&gt;
          &lt;div id = "mainDiv" contenteditable="true"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>But it doesn't work. I don't understand what I'm doing wrong. I spend a lot of time for this problem, but I haven't solved it yet. Help me, please.</p>