Vishnu Vishnu - 1 year ago 146
jQuery Question

check if dynamically added images is loaded

I am creating simple html page where one image is dynamically added to div like below

$(".step3html").html('<img class="mobimg thumbnail" src="img/'+keys+'">');

I want to resize the container after image is loaded fully (it is absolute container) . So how to check if appended image is loaded and call some function where i will run resize function based on full container width.

I tried below code immediately after appending image,It doesn't seem to fire.

$(".mobimg").on('load', function() {

Here is fiddle to test

Answer Source

This code below works.

$(".step3html").html('<img class="mobimg thumbnail" src="">');

$(".mobimg").on('load', function() {

Try this fiddle.

You might have a different issue. Have you checked the value of keys in your console?


Here is a working fiddle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download