<button id="btn">Button</button> <script> btn.onclick = function() { alert('bla-bla'); }; btn.click(); </script>