jqueryjquery-eventsjquery-load

jQuery fire page load event from loaded page


I'm loading a PHP page in a div with $("#div").load("page.php?id-blah")

The page gets loaded correctly and jQuery is functioning properly.

In the page.php I am using the

$(document).ready(function() {
    ...perform things..
})

call but its not fired. What event do I have to use to make perform things run?


Solution

  • Generally, it's not good practice to inject scripts this way. You should look into dynamic loading frameworks (RequireJS, JSPM...).

    Having said that, you could put your script in a normal <script> tag, and make sure that's the last part of the returned content. HTML parsing is sequential, so it will only be parsed after everything else is done.