If the event handler is declared in the markup, it'd be (kind-of) adding presentation logic to HTML.
<button id="btn" onClick="foo()">Click Me!</button>
If the event handler is declared in the script, it'd be (kind-of) hard to look at the code and figure out what button does.
Is there any best-practice for this scenario?
The reason for this question is that I was attaching event handlers on page load via the script. However, I ran into a problem where the DOM element may not be present when the page loads (I'm using KnockoutJS's if binding), and the event is not bound to the handler. To attach the handler as and when the if condition is satisfied would complicate the code further. So now I'm thinking of moving my handlers to the click binding. What might be the potential pitfalls and what best-practices should I follow to avoid them?