document.write alternative

A way to insert content "inline" without using document.write

by Mark James

HTML

<!doctype html>
<html>
    <head>
        <title>document.write alternative</title>
        <meta charset="utf-8"/>
    </head>
    <body>
        <p>Here is some content.</p>
        <!-- load a script; any script -->
        <script type="text/javascript" src="stuff"></script>
        <!-- here's our document.write analog; could just as easily be a remote file -->
        <script type="text/javascript">
            // get the "last" script on the page
            var s = document.getElementsByTagName('script');
            var p = document.createElement('p');
            p.innerHTML = "Here is some dynamic content.";
        </script>
        <!-- load another script; any other script -->
        <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jshint/r07/jshint.js"></script>
        <p>Here is some more content.</p>
    </body>
</html>