Search code examples
jqueryloaddynamic-html

Live() keyword not working on load with dynamic html images


I have images being dynamically added to a page, I don't seem to be able to get the 'load' event working dynamically with live().

This is the code I currently have:

$('#largeImg' + nextUniqueItemID).hide();
$('#largeImg' + nextUniqueItemID).live('load' , function() {
    $('#loader' + nextUniqueItemID).hide();
    $('#largeImg' + nextUniqueItemID).show();
});

with '#largeImg' + nextUniqueItemID being an image that was added to the page earlier in the function and '#largeImg' + nextUniqueItemID being a loading image.

I feel as if I may be misusing "live" as it doesn't really need a listener but to trigger the event immediately.

Thanks for all your help. I tried "bind" and that never triggered. I also tried doing away with the load, but that didn't work. Is there a way to attach a listener to an event that would indicate when the image was done loading?


Solution

  • What I ended up doing was putting the load event directly in my image's onLoad="" event. That worked out.