How to append DOM element of type button in JavaScript? -
how append new buttons, modified values using loop? have used createelement
attribute create button.
var par=document.getelementbyid("numfield"); var ch=document.createelement("input"); ch.setattribute("type","button"); ch.setattribute("value","1"); par.appendchild(ch);
try increasing value , id of button every time add new one. note works without adding id, too, allows access buttons more easily.
var par=document.getelementbyid("numfield"); for(var i=0; i<10; i++){ var ch=document.createelement("input"); ch.setattribute("type","button"); ch.setattribute("value",i); ch.setattribute("id",i); par.appendchild(ch); }
<div id="numfield"> </div>
Comments
Post a Comment