Search code examples
javascriptappendchild

Using document.body.appendChild to append a whole code block?


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?


Solution

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

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