views:

44

answers:

1

I'm using a simple JQuery call to replace some HTML in a DIV tag after an AJAX call.

$("#my_div").html('value');

This works great in the other browsers, but in IE it is just adding to the DIV instead of replacing the HTML.

Any ideas why that would happen?

+2  A: 

call empty() before html()

$("#my_div").empty().html('value')

I noticed that behavior quite a lot and empty() always fixes the issue.

Marek Karbarz
That's weird. I though html() was supposed to replace in jQuery.
Nosredna
Comes down to "I thought IE was suppose to be a compliant web browser"
Nerdling
it's even more bizarre seeing how jQuery appears to be calling empty() internally for the html() function anyways
Marek Karbarz
Maybe it's a DOM timing issue. Should be reported as jQuery bug.
Nosredna
For all jQuery's problems (and its implementation of `empty` is appalling), you shouldn't have to do this; Zarembisty is right. I would love to see a test case for this.
bobince