Javascript examples for DOM HTML Element:Div
Add button to div and attach click event
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {//from w ww . ja va 2 s .com var widget = document.getElementById("widget"); widget.innerHTML = '<button id="mahbutton">Clicky</button>'; var w_btn = document.getElementById("mahbutton"); w_btn.addEventListener("click", function() { console.log("sdf"); } ); }); </script> </head> <body> <div id="widget"> </div> </body> </html>