Ticket #8617 (closed bug: invalid)
Error handlers only being registered on first matching element in IE
| Reported by: | jvz | Owned by: | jvz |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.next |
| Component: | unfiled | Version: | 1.5.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
To reproduce this problem, let's say we have a collection of images, some of which are hosted on a CDN, and others that might not have been synchronised with the CDN yet. To resolve this issue, we might want to set an onError event for all the img's so that they try to load a fallback URL. Example jQuery code:
$(function() {
$("img").error(function(e) {
this.src = this.src.replace("cdn.example.com", "example.com");
});
});
Now the expected behaviour (as demonstrated properly by Firefox, Safari, Chrome, and Opera) is that every img element will have this error handler. However, in IE, only the first img element in the jQuery selection gets the error handler.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

There is a race condition in this test case. You are expecting that an error handler installed on DOM ready will catch an error event that fires when the image does not load. However, the browser may have already attempted to load the image and fired the error event before you attached the handler.
I've created a test case in jsFiddle that shows the problem can happen in other browsers, it's just a matter of timing. If you can modify this to show a problem inside jQuery we can take a look.
http://jsfiddle.net/dmethvin/cNQjY/