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

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -