using the data-custom="" to bind to events
        Posted  
        
            by 
                Dean Peterson
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Dean Peterson
        
        
        
        Published on 2012-06-04T22:00:52Z
        Indexed on 
            2012/06/04
            22:40 UTC
        
        
        Read the original article
        Hit count: 408
        
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
});
© Stack Overflow or respective owner