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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -