Assigning button id as a number inside of an innerhtml - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Assigning button id as a number inside of an innerhtml

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>SO - 29312498</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from w w w. j a v a2  s . c  om*/
var buttons = [];
for (var i = 0; i < 3; i++) {
    buttons.push('<button id="',i,'" onclick="cancelObject(this.id);">',i,"</button>")
}
document.getElementById("tabletext").innerHTML = buttons.join('');
    }

      </script> 
   </head> 
   <body> 
      <div id="tabletext"></div>  
   </body>
</html>

Related Tutorials