Q:

When are JS scripts executed, if they are loaded with jQuery .html() function? 

I'm trying to figure out WHEN JavaScript is executed when one loads a HTML + JS content with .ajax() jQuery function and inserts the content with .html(content).  I've read about domManip, read 

curious about jquery .load(),
Load script tag from the file html,
jQuery .load() / .ajax() not executing javascript in returned HTML after appended,
jQuery .load() html content and execute script,
When is a DOM script loaded by jQuery/Ajax actually executed? 
and much more...

And I've learnt a lot, but have not found out when the script is run:

Will jQuery run the script after parsing and inserting the HTML? ( So I can refer in JS every DOM object from loaded HTML)
Will jQuery run the scripts in the order they are encountered?  What happens when the script is to be loaded with src? 

For example, this is a HTML loaded by .ajax() and then inserted with .html():
<p id="p1">Lorem ipsum...</p>
<script type="text/javascript" src="file.js">
<p id="p2">Dolorem...</p>

On my computer, on three browsers, in file.js I can refer to #p2 and everything works. 

A:

I have created two files:
js_test.html:
<! DOCTYPE html>
<html>
  <head>
  <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  </head>
  <body>
    <div id="div1"></div>
    <p id="clickable">Click!</p>
    <script type="text/javascript">

    $(document).ready(function(){
      $("#clickable").click(function(){
        $.ajax("js_test_insert.html").done(function(content){
          $("#div1").html(content);
        });
      });
    });

  </script>
  </body>
</html>

And js_test_insert.html:
<script type="text/javascript">
alert("Before."); 
$("#inserted p").css("background-color","yellow");
alert("Middle.");  

$(document).ready(function(){
  alert("Inserted ready!"); 
});

</script>
<div id="inserted">
<p>Hello, World!</p>
</div>
<script type="text/javascript">
alert("After."); 

function test() {
  alert("It should not run");
}

</script>

I've tried it on FF 18.0, Chrome 36.0 and IE 11.0 (also using emulation of previous IEs) and:

p#clickable is clicked. 
"Hello, World!"  appears above "Click!". 
Alert "Before." 
"Hello, World!"  becomes yellow. 
Alert "Middle." 
Alert "Inserted ready!" ( I don't understand why .ready() is executed)
Alert "After." 

jQuery firstly inserts HTML, DOM is built, and then JS is executed (in order of appearance). 
EDIT: Why .ready() is executed?  Because the event is still ,,in efect'' (the document is ,,ready'' all the time, isn't it?) --  so adding a new handler of this event causes an immediate execution of the handler. 
Solved.