Monthly Archives: August 2010

Updating div content using JQuery and AJAX

I just noticed something weird when using JQuery ajax ($.get and $.post) to update the content of a div. I use the html function of JQuery to put the content inside the div like this :

$('#someId').html(htmlText);

Everything worked fine with following div :

<div id="someId"></div>

But, as I work with xml a lot, I am used to writing empty tags as such :

<div id="someId"/>

Suddenly, the div would not get the content from the html function anymore! My only possible explanation is that the <div id="someId"></div> implicitly contains an empty text node (which will be replaced with the html), while the <div id="someId"/> does not have any content at all.