title: Standard way to append multiple new elements and register a click event for each (jQuery Beginner!)
body: <p>I'm a jQuery beginner. I'm adding a bunch of new images into a div. I'd like each of these images to respond to a click.</p>
  
  <p>My initial, and in hindsight foolish code, looked like this:</p>
  
  <pre><code>for (var i = 0; i &lt; 10; i++) {
      $("div#stargrid").append("&lt;img class='clickme' src='http://placehold.it/90x90' alt='90x90 placeholder image' /&gt;").click(my_event_handler);
  }
  </code></pre>
  
  <p>Now, I've worked out that that's dumb, because the chaining doesn't work how I thought it did, so (I think) that actually adds the click event handler ten times to my <code>div#stargrid</code>, not once to each <code>img</code>.</p>
  
  <p>I found one solution that seems to work for me, just to separate these operations out and bind the click event to all the images afterward:</p>
  
  <pre><code>for (var i = 0; i &lt; 3; i++) {
      $("div#stargrid").append("&lt;img class='clickme' src='http://placehold.it/90x90' alt='90x90 placeholder image' /&gt;");
  }
  $(".clickme").click(imageclick);
  </code></pre>
  
  <p>My question is: is that the "right" way to do it?</p>
  
  <p>I realise this may be subjective, but what I'm looking for here is the "standard" way to do this kind of thing in jQuery, preferably with some reasoning as to why it's a good way. I had a look around and couldn't find much in the way of examples of doing what I'm doing here.</p>
  
  <p>Thanks!</p>