this is my javascript
<head runat="server">
<script type="text/javascript" language="javascript">
function createQuestionPanel() {
var element = document.createElement("Input");
element.setAttribute("type", "button");
element.setAttribute("value", "button");
element.setAttribute("name", "button");
var div = '<div>top div</div>';
div[0].appendChild(element);
}
function formvalidate() {
}
</script>
</head>
<body onload="createQuestionPanel()">
</body>
</html>
it is throwing error "AppendChild is not a function" . I tried to search for solution .. it was suggested that on the place of
div.appendChild(element);
this should be posted
div[0].appendChild(element);
it didnt change the error . Please suggest
Your
div
variable is a string, not a DOM element object:Strings don't have an
appendChild
method. Instead of creating a raw HTML string, create the div as a DOM element and append a text node, then append the input element:Try the following:
In this
"div" is not a DOM object,is just a string,and string has no string.appendChild.
Here are some references that may help you on appendChild method:
Just change
to