Why promote the (ab)use of the class attribute for binding user interface behavior?<p>It's 2013, people that write blogposts should be directing their readers (imo) to using the (html5) data-* attributes (which works equally simple) and actually removes the declaration and mixture of behavior and styling from your css.<p>For instance your button example:<p><pre><code> <button data-behavior='addtocart' data-somespecialparameter='iamspecial' class="add-item">Add to Cart</button>
</code></pre>
Would behave on some javascript:<p>jQuery:<p><pre><code> $(document.body).on('click' 'button[data-behavior="addtocart"]', myHandlerFunction);
</code></pre>
MooTools<p><pre><code> document.body.addEvent('click:relay(button[data-behavior="addtocart"])', myHandlerFunction);
</code></pre>
Handler:<p><pre><code> function myHandlerFunction(ev) {
console.log("I just got clicked. ", this.getAttribute('data-somespecialparameter'), this);
}
</code></pre>
Also, using observers on a container element makes sure that you can dynamically add and remove html elements without having to worry about cleaning up the even handlers. (binding it all on document.body or the nearest container can be debatable for speed reasons, but this is up to you)