title: How to simulate a mouse click using JavaScript?
body: <p>I know about the <code>document.form.button.click()</code> method. However, I'd like to know how to simulate the <code>onclick</code> event.</p>
  <p>I found this code somewhere here on Stack Overflow, but I don't know how to use it :(</p>
  <pre><code>function contextMenuClick()
  {
    var element= 'button';
    var evt = element.ownerDocument.createEvent('MouseEvents');
  
    evt.initMouseEvent('contextmenu', true, true, element.ownerDocument.defaultView,
                       1, 0, 0, 0, 0, false, false, false, false, 1, null);
  
    element.dispatchEvent(evt);
  }
  </code></pre>
  <p>How do I fire a mouse click event using JavaScript?</p>