Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

create multiple buttons in javascript

let i = 1;
let body = document.getElementsByTagName("body")[0];

for (i; i <= 20; i++) {
  let button = document.createElement("button");
  button.innerHTML = 'Button '+i;
  body.appendChild(button);
  button.addEventListener ("click", function() {
    alert(this.innerHTML);
  });
}
Source by www.ianposton.com #
 
PREVIOUS NEXT
Tagged: #create #multiple #buttons #javascript
ADD COMMENT
Topic
Name
8+6 =