I'm trying to use appendChild within Javascript to create a link that has a onClick attribute. I can't seem to make it work or find how to do this simple task.
var link=document.createElement("a");
link.appendChild(document.createTextNode("Link"));
link.href = '#';
link.onclick = 'loadScript()';
document.body.appendChild(link);