using the data-custom="" to bind to events
- by Dean Peterson
I'm pretty sure I'm gonna get slammed on this.
I love using the data-whatever attribute to bind events to.
It feels very clean to me and helps reserve my class attribute for just styling.
I know this selector is among the slowest, so I don't use it when there are a lot of elements.
Would love to hear compelling arguments against this.
$("body").delegate("[data-action]", "click", function(){
var action = $(this).attr("data-action");
//route action to appropriate function
});