Javascript examples for DOM HTML Element:Input Button
Create button and add an onclick to each one
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="application/javascript" language="JavaScript 1.7"> window.onload=function(){/*from ww w . j av a 2s .co m*/ for (var i = 0; i < 10; i++) { var link = document.createElement('button'); link.textContent = i; let j = i; link.addEventListener('click', function() { console.log(j); }, false); document.body.appendChild(link); } } </script> </head> <body> </body> </html>