Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the jQuery docs may be a little misleading on this one, unless it is doing something really special to get past the problem.</p> <p>Load events on elements such as images do not bubble up.<sup><a href="http://en.wikipedia.org/wiki/DOM_events" rel="noreferrer">1</a></sup><sup>, </sup><sup><a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-htmlevents" rel="noreferrer">2</a></sup></p> <p>Since they don't bubble up, the <code>document</code> does not know whether a load event had been fired.</p> <p>Because the <code>document</code> doesn't know about the load event, live will render useless as live relies on events bubbling up to the document, and once they do, it matches the event target with the selectors it already has on file, and if anything matches, the event handler is triggered for that element.</p> <p>For instance, suppose you were to register the following live event:</p> <pre><code>$("#container &gt; input").live("change", function() { alert("changed"); }); </code></pre> <p>then jQuery will add a change event listener on the document object if it doesn't already exist (similar to):</p> <pre><code>$(document).bind("change", function() { .. }); </code></pre> <p>When any change event bubbles up to the document, it runs through each registered selector, and checks if any of the resulting nodes for a given selector include the event target (element that the event originated from). If it's present, then the corresponding "live" event handler is fired for that event target.</p> <p>None of this is possible if the document would not know about the event in the first place.</p> <p>Unless I am mistaken and jQuery has some secret sauce for doing this, you should directly bind the load event instead of doing it through live.</p> <pre><code>$("selector").bind("load", function() { .. }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload