javascript - using the data-custom="" to bind to events -
i'm pretty sure i'm gonna slammed on this.
i love using data-whatever attribute bind events to.
it feels clean me , helps reserve class attribute styling.
i know selector among slowest, don't use when there lot of elements.
would love hear compelling arguments against this.
$("body").delegate("[data-action]", "click", function(){ var action = $(this).attr("data-action"); //route action appropriate function });
$("body").delegate("[data-action]", "click", function(){ ^^^^-------------------------- body high node. ^^^^^^^^--------------- on should used instead of delegate. ^^^^^^^^^^^^^ attribute selector slow selector.
Comments
Post a Comment