This:
Code:
node1.onclick = "alert(666)";
won't assign an onclick event even to an existing element. It is only assigning a string to the onclick attribute. Try:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script type="text/javascript">
var node1 = document.createElement("span"), func1 = function(){alert(666);};
node1.appendChild(document.createTextNode("666"));
node1.onclick = func1;
document.body.appendChild(node1);
</script>
</body>
</html>
Bookmarks