Tie a button to a javascript function
html, javascript
Solution
It's considered better to attach it via JavaScript. This falls under the category of "Unobtrusive JavaScript". (more specifically here the separation of behavior from the layout)
document.getElementById('YourID').onclick = nameOfFunctionToBeCalled;
Problem
I have a button in html: ``` <button id="MyButton" onclick="return DoSomething()">Click Me</button> ``` Is it better to put the "onclick" property in the html or use javascript/DOM to attach a callback to the button click?