There are multiple ways of doing this.
Firstly you could use a marker and then remove it:
<div id="mydiv" class="not-initialized">
...
</div>
with:
$("#mydiv").click(function() {
if ($(this).hasClass("not-initialized")) {
$(this).removeClass("not-initialized");
// append content
} else {
$(this).toggle();
}
});
Secondly, you could change event handlers:
$("#mydiv").click(append_content);
function append_content() {
...
$("#mydiv").unbind("click", append_content).click(toggle_display);
}
function toggle_display() {
$(this).toggle();
}
Or you could do things like testing the div to see if the content is there.