<!-- code inside the onclick attribute is wrapped inside a function and assigned to onclick property of that button object --> <button id="button_1" onclick="alert('clicked');">click me 1</button> <button id="button_2">Click me 2</button>
window.document.getElementById("button_2").onclick = function(){ alert("clicked"); }