Onload callback for dynamically loaded images

Posted About 13 years ago. 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
Over 11 years ago
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)