title: JavaScript how to program button to act like a mouse click?
body: <p>I'm trying to program a button to act like a mouse click event using ONLY JavaScript (NO jQuery)</p>
  <p>For example if you have:</p>
  <pre><code>&lt;h2&gt; Please select your fav: &lt;/h2&gt;
  &lt;input type=&quot;checkbox&quot; id=&quot;check1&quot; class=&quot;checkbox&quot; /&gt;&lt;label for=&quot;check1&quot;&gt;C++&lt;/label&gt;
  &lt;input type=&quot;checkbox&quot; id=&quot;check2&quot; class=&quot;checkbox&quot; /&gt;&lt;label for=&quot;check1&quot;&gt;Java&lt;/label&gt;
  &lt;input id=&quot;submitAnswer&quot; type=&quot;button&quot;  value = &quot;Submit your Answer&quot; onClick=&quot;submitAnswers()&quot;&gt;/input&gt;
  
  &lt;input id=&quot;mouseClick&quot; type=&quot;button&quot;  value = &quot;CLICK&quot; onClick=&quot;mouseClick()&quot;&gt;&lt;/input&gt;
  </code></pre>
  <p>So, I have a focus method, which checks what element has focus.
  I need to program another button to act like the mouse click, so in case of clicking on the checkboxes, it should check/uncheck it. and if the focus on the submit button, it should trigger the function.</p>