Skip to main content

Bug Tracker

Side navigation

#8617 closed bug (invalid)

Opened March 24, 2011 02:32PM UTC

Closed March 24, 2011 07:01PM UTC

Error handlers only being registered on first matching element in IE

Reported by: jvz Owned by: jvz
Priority: undecided Milestone:
Component: unfiled Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

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("", "");

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.

Commented test case

Attachments (0)
Change History (3)

Changed March 24, 2011 03:04PM UTC by dmethvin comment:1

owner: → jvz
status: newpending

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.

Changed March 24, 2011 03:08PM UTC by jvz comment:2

status: pendingnew

It's very possible that the bug I'm finding is completely due to that. Sorry, I guess I didn't fully understand how the error event is fired.

Changed March 24, 2011 07:01PM UTC by dmethvin comment:3

resolution: → invalid
status: newclosed

Based on #8619 being opened I'm closing this one.