Breaking change in IE9 re: each() and "this"
Hello.
I've discovered some unexpected behavior to do accessing element attributes within an each() loop.
In IE8 the following code works:
jQuery.each(aPeople, function(idx)
{
var aDays = $('TD[PersonId=' + this.PersonId + ']');
}
I can read the PersonId attribute from the TD element using "this.PersonId".
However, the code does not work in IE9. It returns "undefined".
I've changed the code to this:
jQuery.each(aPeople, function(idx)
{
var aDays = $('TD[PersonId=' + $(this).attr('PersonId') + ']');
}
This works in both IE8 (in IE9 but running compatibility mode) and IE9.
Is the first version of the code is incorrect and should never have been used or is there a bug in IE9?
The version of jQuery is v1.3.2. I realise this is quite old but I'm concerned that dropping in a more recent version might cause more headaches.
Any advice/thoughts appreciated.
Cheers,
Ben