This is a bit of an oddball use case, but I have my reasons:
I\'d like to be able to write
As far as I know, you can't. If the markup looks like
<script type="text/javascript" src="first.js"></script>
<script type="text/javascript" src="second.js"></script>
you can't access the second script element from within first.js
, as it hasn't been added to the DOM at the moment the first script runs (even not if you assign an id
to the second element). It doesn't matter whether the code of second.js
is put inline or in an external file.
The only thing I don't understand is your second point. First you say that you can't control the markup of the document, but then you state it is possible to load second.js
dynamically (using AJAX).