Question

Is it possible to append a whole code block using appendChild? This is what I want to append:

<script type="text/javascript" src="some.js"></script>
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="styles-ie.css" media="all" />
<![endif]-->
<!--[if lt IE 7]>
<script type="text/javascript" src="85d6d1c5f8f9c87ae016eae0ee6994c7.js"></script>
<![endif]-->

I guess I cant append it using appendChild?

Was it helpful?

Solution

If you are using pure JavaScript, you could use this:

var body = document.body;
body.innerHTML += 'Whatever you want to append.';

OTHER TIPS

function addLABjs(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "YourOtherScript.js");
    script.addEventListener('load', function () {
        var script = document.createElement("script");
        script.textContent = "(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}

// the guts of this userscript


function main() {
    $LAB.script("YourOtherScript.js").wait()
        .script("YourOtherScript.js")
        .script("YourOtherScript.js").wait();

    $(document).ready(function () {
    });
}

addLABjs(main);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top