JQuery .load() callback function

Dan picture Dan · Oct 20, 2010 · Viewed 47.1k times · Source

I've seen lots of questions and solutions to problems like this but nothing has worked for me. I have this:

function() {
    $("#bdiv").load("bosses.php #icc10n",function(){
        return $("#bdiv").html();
    });
}

But it's not working. To clarify, I want to load content into #bdiv and then return the contents of #bdiv. But it seems that $("#bdiv").html() is being returned before the content is loaded even though I've put it in a callback function.

Answer

Petah picture Petah · Oct 20, 2010
$("#bdiv").load("bosses.php #icc10n",function(data){
    // use the data param
    // e.g. $(data).find('#icc10n')
});