0

I am trying to attach a load event handler to images like this:

$(document).on('load', '.mini img', function(){
    $(this).prev().hide();
    $(this).fadeIn(500);
});

Can anyone explain why this isn't working? Images are simply formed using information gotten through an ajax request and inserted using append method. A lot of people had this problem and i wonder what the solution was.

Maxon
  • 1
  • 1
  • 2
    You can't delegate the load event, it doesn't bubble. Show us how the images are created. – adeneo Aug 06 '14 at 19:02
  • I believe that the _jQuery selector_ `.mini img` is evaluated at run-time meaning that you're not really listening for all _load_ events that hit `document` – Paul S. Aug 06 '14 at 19:02
  • @PaulS. You're right, but what does that have to do with the OP? They don't seem to mention wanting to know about **all** load events. And the problem is what adeneo says - that event doesn't bubble – Ian Aug 06 '14 at 19:05
  • 1
    @Ian I totally forget some events don't bubble by default – Paul S. Aug 06 '14 at 19:09
  • @PaulS. Me too, I only recently read it somewhere and reminded me that specifically `load` doesn't (and then adeneo's comment reminded me too). It is funny though, because I think a few events don't naturally bubble, but in jQuery event handling, it causes them to anyways – Ian Aug 06 '14 at 19:09
  • Thank you guys. Thank you and "May the force be with you" and "Live and prosper". – Maxon Aug 06 '14 at 19:34

0 Answers0