jquery html callback

前端 未结 4 1687
渐次进展
渐次进展 2020-12-06 17:08

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\         


        
4条回答
  •  执笔经年
    2020-12-06 17:28

    Hopefully somebody has a better solution than myself. A quick workaround is to use setTimeout() to delay your next calls, giving your HTML block enough time to load (since the load time is so miniscule).

    $('#some_div').html('
    some content
    '); // set timeout for 250 milliseconds setTimeout(callbackFunction, 250); function callbackFunction() { // do some cool sh*t }

    Note, however, that if you wanted to pass any variables to your function, you could do the following:

    $('#some_div').html('
    some content
    '); // set timeout for 250 milliseconds var myParam = 'value'; setTimeout(function() { callbackFunction(myParam); }, 250); function callbackFunction(myParam) { // do some cool sh*t alert(myParam); }

提交回复
热议问题