<button>Button</button> <script> var btn = document.body.children[0]; btn.onclick = function() { alert('bla-bla'); }; btn.click(); </script>