Onload callback for dynamically loaded images

Updated . Posted . Visible to the public.

Sometimes you need to dynamically load an image and do something as soon as its loaded (when for example its size is already available).

With jQuery, this seems to work across browsers:

$('<img>')
  .attr('src', '')
  .load(function() {
    alert('fully loaded!');
  })
  .attr('src', '/the/real/image/url');
Tobias Kraze
Last edit
Keywords
resize, center
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2011-03-22 21:58)