html - how to access innerHTML of button created dynamically through JavaScript -


this javascript function used creating dynamic buttons. want access innerhtml of button.

function mynumber() {        var i,j = 1, num = 0; # used making 3 buttons in row , j used repeat same process no of time , num int text on button     {         (i = 1; <= 3; i++) {                    var btn = document.createelement("button"); # create button using javascript             var txt = document.createtextnode(num++); # creat text on button             btn.appendchild(txt); # attached text on button             btn.id = ('obj'+ k++) ;               document.getelementbyid("btnsize").appendchild(btn); # atache button text in div          }          var next = document.createelement("br");         document.getelementbyid("btnsize").appendchild(next);         j++;     }      while(j<4)           }  ("btn").click(function()                      {                        var val = document.getelementbyid(this.id).innerhtml;                            document.getelementbyid("demo").value = val;                                     })  

you can apply css class button shown in https://jsfiddle.net/3u71kzrh/

declare style below in stylesheet or between <style> , </style> tag in html <head>.

.aclassname{    width:40px;    height:40px; } 

add following line below code create button element.

btn.classname = "aclassname"; 

Comments