jQuery html method and IE7
Facts - HTML and Javascript
Wednesday, 29 April 2009 07:55

I am testing my websites with Firefox and Internet Explorer. While testing a page with jQuery 1.3.2 code in IE7 I encountered some problems. The same problem is also present in jQuery 1.2.6 in combination with IE7.

When setting the contents of an existing div with the html method its corresponding jQuery object at least one other div element after this div disappeared. The div for which the html() method was invoked was in the HTML code itself, it was not created from javascript.

It turned out that the jQuery html() method calls the method empty() on an existing DOM object. So I tried using empty() instead of html() on the div, and I saw again the same problem with IE7: it deleted another div after the div I invoked the empty() method for.

I did not have this problem when setting the contents of the div with innerHTML attribute. In this case I had another workaround. I did not have to use a statically created div. Instead I could create the div on the fly using $('#someElement').append("<div id='myDiv'/>"). Then I set the contents of this new div using its append method: $('#myDiv').append('new contents');

Last Updated on Wednesday, 29 April 2009 08:15