WORKING WITH THE DOM
In many cases, working with the DOM is fairly straightforward, making it easy to re-create with JavaScript what normally would be created using HTML code. There are, however, times when using the DOM is not as simple as it may appear. Browsers are filled with hidden gotchas and incompatibilities that make coding certain parts of the DOM more complicated than coding its other parts.
Dynamic Scripts
The <script>
element is used to insert JavaScript code into the page, either by using the src
attribute to include an external file or by including text inside the element itself. Dynamic scripts are those that don’t exist when the page is loaded but are included later by using the DOM. As with the HTML element, there are two ways to do this: pulling in an external file or inserting text directly.
Dynamically loading an external JavaScript file works as you would expect. Consider the following <script>
element:
<script src="foo.js">...