title: How to check if image is clicked after creating it through JS?
body: <p>I have created an image in js after clicking on a button. How do I perform an action on the image when it is clicked <em>after</em> it has been rendered? Here is the code I tried:</p>
  
  <pre><code>function sayhi(){
  
      for (var m = 0; m &lt;animals.length;m++){
          var image = document.createElement('img');
          image.src = "animalgameback.jpg";
          image.id = animals[m];
          document.getElementById('body').appendChild(image); 
          image.onclick = flip(this);
  
      }
  }
  </code></pre>
  
  <p>However when I set the onclick image attribute, it performs the task only before the image has even been rendered. Any suggestions?</p>