title: JavaScript - document.getElementByID with onClick
body: <p>I'm trying to code a simple game in an HTML document just for fun. In it, there is an image which adds to your score when clicked.</p>
  <p>I created a simple <code>if</code> statement within the score-adding function which should change the image and what its <code>onClick</code> value is...</p>
  <pre><code>if (foo == 1) {
      document.getElementById(&quot;test&quot;).src = &quot;images/test2.png&quot;;
      document.getElementById(&quot;test&quot;).onClick = &quot;foo2()&quot;;
  }
  </code></pre>
  <p>...but it doesn't work. The image will be successfully changed, but the actual onClick remains the same. Checking the console, it throws no errors, either.</p>