IEnumerable
IEnumerable

Reputation: 3790

jQuery after load complete event

I'm using .load() and .show() to dynamically load some HTML.

//load the html
$('#mydiv').load('some_url');
        
            
 // Display
$('#mydiv').show();

But here I need to call a JavaScript function that only exist in the dynamic content, how can I tell if the .load() is complete ?

Upvotes: 14

Views: 40973

Answers (4)

Rituraj ratan
Rituraj ratan

Reputation: 10388

$( "#mydiv" ).load( "url", function() {
  alert( "Load was performed." );
});

reference load

Upvotes: 5

Alexander Kobelev
Alexander Kobelev

Reputation: 1379

$('#mydiv').load('some_url', function(responseText, textStatus, XMLHttpRequest){
  console.log("Content Loaded!");
});

Look at this

Upvotes: 2

Royi Mindel
Royi Mindel

Reputation: 1258

The load function get a callback function for complete

('#mydiv').load('some_url', function() {
  alert( "Load completed." );
});

http://api.jquery.com/load/

Upvotes: 7

CodingIntrigue
CodingIntrigue

Reputation: 78565

Use the callback for .load:

$('#mydiv').load('some_url', function() {
    // This gets executed when the content is loaded
    $(this).show();
});

Upvotes: 41

Related Questions