Is there a callback for the html() function or a way to check that it is finished. For example:
$(\"#some_div\").html(\'something here\');
if($(\"#some_div\
Chetan Sastry's answer(the highest answer now) is not 100% correct.
$('#some_div').html('some content'); // code 1
$('#new_div').click(function(){ }); //code 2
I don't know why, but in some cases, code 2 will be executed before code 1 finishing. There is a short time less than 0 millisecond between code 1 and code 2. It should be some special executing orders in Javascript.
You have to use cballou's way(the floor answer =_=!) to solve the problem. e.g.
var sync = function(fn, millisec){
var m = millisec ? millisec : 0; //in face, 0 is enough
return setTimeout(fn,m);
};
$('#some_div').html('some content'); // code 1
var code2 = function(){
$('#new_div').click(function(){ }); // run code 2, here
};
sync(code2);