Attaching events in JavaScript

Posted by R0MANARMY on Stack Overflow See other posts from Stack Overflow or by R0MANARMY
Published on 2010-04-10T20:32:33Z Indexed on 2010/04/10 20:43 UTC
Read the original article Hit count: 309

As comment to one of the questions here a commenter wrote (emphasis mine):

... By using an inline "onclick" you are doing a similar thing, but it is harder to maintain and more prone to issues. The JavaScript community as a whole has been moving away from inline JavaScript for a while now.

This was referring to attaching events to HTML elements using

$("#someID").click(function(){
    do something here...;
});

rather than

<a id="someID" onclick="someFunction();">

Has there really been a shift away from the old school way of declaring events inline, and if so, what are the benefits of one of the other?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about javascript-events