title: Image onload for static images
body: <p>I know that for the image onload to work you have to set the src after the onload handler was attached. However I want to attach onload handlers to images that are static in my HTML. Right now I do that in the following way (using jQquery):</p>
  
  <pre><code>&lt;img id='img1' src='picture.jpg'&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>$('#img1').load( function() {
   alert('foo');
  })
  .attr('src', $('img1').attr('src'));
  </code></pre>
  
  <p>But this is rather ugly and has the obvious flow that it can only be done for selectors that match only one image. Is there any other, nicer way to do this?</p>
  
  <p><b>edit</b><br>
  What I meant by that it can only be done for selector that match only one image is that when doing this:</p>
  
  <pre><code>&lt;img class='img1' src='picture.jpg'&gt;
  &lt;img class='img1' src='picture2.jpg'&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>$('.img1').load( function() {
   alert('foo');
  })
  .attr('src', $('.img1').attr('src'));
  </code></pre>
  
  <p>That both images will have src='picture.jpg'</p>