add element to the DOM with JS

Posted by john on Stack Overflow See other posts from Stack Overflow or by john
Published on 2010-03-13T19:10:28Z Indexed on 2010/03/13 19:15 UTC
Read the original article Hit count: 228

Filed under:
|
|

I want add element with JS. I have code:

var collection = document.getElementsByTagName('body');<br>
var a = document.createElement('div');<br>
        a.innerHTML = 'some text';<br>
            collection.item(0).firstChild.appendChild(a);<br>

and simple HTML:

<html>
<head>
</head>
<body>

</body>
</html>

When is misstake?

© Stack Overflow or respective owner

Related posts about html

Related posts about JavaScript