I'm trying to add button inside the div
the div
element when i'm click to a button.
The following JS
code:
function doThis(){
var btn= document.createElement("input");
btn.type="submit";
btn.value="button";
var child=document.getElementById("child");
var submit=document.getElementById("submit");
child.insertAfter(btn, submit);
}
and html
markup:
<div id="parent" class="parent">
<div id="child" class="child">
<input type="text" class="text"/>
<input id="submit" type="submit" onclick="doThis()"/>
</div>
<div>
In console i have error message: Uncaught TypeError: Object #<HTMLDivElement> has no method insertAftert
. How to fix this?JSFIDDLE