Javascript examples for DOM:Event
Add event to element when DOM is loaded
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <div id="TABLE"> </div> <script> window.onload = function () { var table = window.document.getElementById("TABLE"); var button = document.createElement("BUTTON"); button.id = "BUTTON_ID"; button.innerHTML = "Button"; button.onclick = function() { console.log('clicked'); };// ww w. j a va 2 s. co m table.appendChild(button); } </script> </body> </html>