javascript - Not Using an Anonymous Function w/ Jquery Events -


in program, have click event same thing many buttons, except class in small part of event handler function different each one. right now, i'm using anonymous function this. function attached event pretty long, , anticipate there being many buttons ( maybe 60 or so? ). copy , paste working function have 60 times, make javascript file huge.

what do, define event handler function outside of on() function, can $('#some_button').on('click', my_event_handler("my_arg") );
simplify code.

i made js fiddle kind of gives small example of i'm trying do:

http://jsfiddle.net/asmmf/

the problem, can't work!

i'm going go see ted, , try out solutions problem when back.

thanks can provide me!

$('#some_button').on('click', my_event_handler("my_arg") ) 

should be:

$('#some_button').on('click', null, "my_arg", my_event_handler); 

live demo


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -