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

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

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

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -