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.