Im using .load() and .show() to dynamicly 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 ?
The onload event occurs when an object has been loaded. onload is most often used within the <body> element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.).
after page loading? Method 2: Using the ready() method: The ready() method in jQuery is used to execute code whenever the DOM becomes safe to be manipulated. It accepts a handler that can be passed with the function required to be executed. It will now invoke the function after the page has completed loading.
Method 1: Using onload method: The body of a webpage contains the actual content that is to be displayed. The onload event occurs whenever the element has finished loading. This can be used with the body element to execute a script after the webpage has completely loaded.
Use the callback for .load:
$('#mydiv').load('some_url', function() {
// This gets executed when the content is loaded
$(this).show();
});
The load function get a callback function for complete
('#mydiv').load('some_url', function() {
alert( "Load completed." );
});
http://api.jquery.com/load/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With