The .load() function purposefully extracts <script> tags from the loaded content. When you give it a simple download URL, it will execute scripts after loading the content and adding it to the DOM. However, if you use the trick of adding a selector after the URL in the first argument:
$('#foo').load("http://some.domain.com/blah #special-div");
then it breaks the <script> tags, but does not execute them.
Why? I dont know.
Now note that loading the entire page from the <html> down into the element of another page will create some kind of Frankenstein DOM monster, if the browser does it at all. Typically, when you use ".load ()" to capture pieces of content to refresh a page, your server should respond with a fragment of the page, not everyone. The jQuery deal with selector resolution after the actual URL is for you to cut out a page fragment, which is really cool, but has the disadvantage that the scripts will not be executed in this case.
source share