user701510
user701510

Reputation: 5773

cannot get simple appendChild function working

I am testing javascript code on W3schools' site and I cannot get the appendChild function working. Hope its not a dumb error.

here it is:

<script type="text/javascript">

function append()
{
var node = document.getElementById(“history”);
node.appendChild(document.createTextNode("text"));
}

window.onload = append;
</script>

<div id="history"></div>

Upvotes: 0

Views: 254

Answers (1)

Felix Kling
Felix Kling

Reputation: 817198

You don't have proper double quotes (I don't know what the others are called):

document.getElementById(“history”);
//                      ^       ^ 

This throws the error:

Uncaught SyntaxError: Unexpected token ILLEGAL

It works with:

document.getElementById("history");

DEMO


OT: w3schools is not a good resource for learning (http://w3fools.com/). Better have a look at the Mozilla documentation: https://developer.mozilla.org/en/javascript

Upvotes: 3

Related Questions