IE gotcha with jQuery.clean()
Here's a fun IE issue I just chased down today.
In some cases $(...).load() worked in FF but not IE. Specifically, the
element's contents were being replaced by an empty div.
I've traced it down to the fun combination of jQuery.clean() and an
extraneous </div> at the end of the markup coming back from the ajax
request. Here's the relevant part of jQuery.clean() (In the following,
wrap has the value [ 1, "div<div>", "</div>" ].):
// Go to html and back, then peel off extra wrappers
div.innerHTML = wrap[1] + elem + wrap[2];
// Move to the right depth
while ( wrap[0]-- )
div = div.lastChild;
In IE, the extra </div> at the end of elem becomes an empty DIV
element
in the DOM and, since it's at the end, it's the lastChild that gets
pulled out in the loop.
Obviously having such dangling tags is a bug at our end, which I've
fixed. That being said, whichever bug[1] this MSIE-specific fallback
wrap value was introduced to solve might be best dealt with
differently--even after calling clean we can't be sure div only has
one
child after running elem through IE's innerHTML parser.
Ted
1. Was it http://dev.jquery.com/ticket/1210? This wrap hack first
appears in http://dev.jquery.com/changeset/2783, but that was
addressing several issues.