Thursday 4 March 2010

jQuery .html() Problems in Internet Explorer

So I've developed my web application in firefox, all seems to be working fine but before I check-in I quickly check the application in the other major browsers; they all work great. All work great APART from IE!

In IE it turns out that the jQuery .html() attribute won't replace contents of first matched element unless the new HTML is valid (i.e. opening and closing tags match). Guess I can't complain with IE not liking the HTML I'm giving it when its imperfect. If only IE practiced what it preached! :)

// This fails in IE...
$('#someDivID').html("<div id='newDivID'><p>hello world</p></div></div>");

// This works in IE...
$('#someDivID').html("

hello world

");

That is all.

3 comments:

  1. I had the same issue in IE and after reading this, i checked all my tags and solved my issues. Thanks !!!!

    ReplyDelete
  2. thanks alot!!! thought my whole application wont work completely with IE..did this..and it totally worked!!
    THANKS!

    ReplyDelete