<head>
<title>untitled</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Geany 0.21" />
<script type="text/javascript">
var newdiv = document.createElement('div');
var divIdName = aaa;
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML ='adadsdsfd';
document.body.appendChild(newdiv);
</script>
</head>
<body>
<div id="aa">
ddgdf
</div>
</body>
</html>
I am trying to append a simple html element by javascript but it is not working can someone please point out what is wrong.
aaaindivIdNameis treated as a variable, but I don't see it defined anywhere. Maybe you wanted"aaa"(a string)?aaais undefined.aaabeing undefined you try to accessdocument.bodybefore it's available. Move the script to the end of your document.