changwarez
changwarez

Reputation: 1

Detecting if html() is loaded in jquery

How can i check if one html is being fully loaded ? And then i want to do something. If:

$('#load').html(1);

is ended i want to wait couple of seconds and then load another

$('#load').html(2);

How can i see when an html is being fully loaded ?

Upvotes: 0

Views: 4947

Answers (3)

Jivings
Jivings

Reputation: 23250

html() is a synchronous operation.

The second html function wont start until the first is complete. Unless the html is loading some dynamic content?

EDIT: It is loading dynamic content. In which case you could do this instead:

$('#load').load('ajax/test.html', function() {
    // callback runs when first load is finished
    $('#load').load('ajax/test2.html');
});

Upvotes: 3

Oded
Oded

Reputation: 499002

Use the ready() event handler:

Description: Specify a function to execute when the DOM is fully loaded.

$(document).ready(function() {
  // Do stuff with the HTML
});

Upvotes: 1

Thomas Clayson
Thomas Clayson

Reputation: 29925

$('#load').html(...).load(function(){
  // what to do when its loaded.
});

Upvotes: 1

Related Questions