Skip to main content

Bug Tracker

Side navigation

#5315 closed bug (invalid)

Opened October 01, 2009 01:56PM UTC

Closed October 02, 2009 01:07AM UTC

bind and attr error on IE8 and IE7

Reported by: ecentinela Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:
Description

This code fails

var $img = $(new Image).load(function() {

alert($img)

}).attr('src', 'image.jpg');

But this not

var $img = $(new Image).load(function() {

alert($img)

});

$img.attr('src', 'image.jpg');

In the first example, alert shows undefined. In the second examples, it returns the jquery node.

This fails in IE 7 and IE 8. IE 6 seems that is OK.

Attachments (0)
Change History (1)

Changed October 02, 2009 01:07AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

I don't think this is a jQuery bug, although it's an interesting case. It appears that when image.jpg is on your local drive, IE synchronously loads it and fires the onload event before it returns from the chained function. So, $img is not assigned the value by the time the event fires. If you replace the .attr() with an image that must be retrieved from the network, the request is synchronous and behaves the way you expect.