How to wait till div is loaded from remote file ?

Discussion in 'jQuery' started by juggalox, Jun 1, 2012.

  1. #1
    Hi all , i have a problem. Say I have the following code

    jQuery("#scr").load("http://example.com/sample.html");
    alert ("done");


    I want the alert to display only after the div has loaded the remote link. Currently when i do this , alert displayes even before its loaded.

    Thanks !
     
    juggalox, Jun 1, 2012 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Здраствуй Hi,

    The .load() can take a callback to be fired on completion:
    
    jQuery('#scr').load('http://example.com/sample.html',function(){
    alert ('done');
    });
    
    Code (markup):
     
    koko5, Jun 2, 2012 IP