Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery after load complete event

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 ?

like image 380
IEnumerable Avatar asked Oct 07 '13 07:10

IEnumerable


People also ask

What event do you use to perform something after the page has finished loading?

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.).

How can we call a method after page load in jQuery?

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.

How do you execute a function when a page is fully loaded?

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.


2 Answers

Use the callback for .load:

$('#mydiv').load('some_url', function() {
    // This gets executed when the content is loaded
    $(this).show();
});
like image 68
CodingIntrigue Avatar answered Sep 19 '22 22:09

CodingIntrigue


The load function get a callback function for complete

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

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

like image 39
Royi Mindel Avatar answered Sep 19 '22 22:09

Royi Mindel