Bug Tracker

Modify

Ticket #5315 (closed bug: invalid)

Opened 5 years ago

Last modified 5 years ago

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:
Blocking: Blocked by:

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.

Change History

comment:1 Changed 5 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.