when changing I want t...">

Call multiple functions from one event with unobtrusive javascript

I have an input element

<select id="test"></select> 

when changing I want to call several functions

 $('#test').change(function1, function2); 

now only alerts apply.

 var function1 = function(){alert('a');}; var function2 = function(){alert('b');}; 

Only the second function is called. I know this because of warnings and brake points. I know that one way to fix this would be to call function1 and function2 from another function, but I would like to avoid it.

+4
source share
5 answers

I prefer not to use anonymous functions, so I would create a new function and put all the work inside it.

 $('#test').change(onSelectChange); var onSelectChange = function() { function1(); function2(); } 
+5
source

You can always link them:

 $('#test').change(function1).change(function2); 

DEMO: http://jsfiddle.net/dirtyd77/uPHk6/11/

+3
source

You can do it -

 $('#test').change(function1); $('#test').change(function2); 
0
source

You can do it as follows:

 $('#test').change(function(){function1(); function2();}); 
0
source

Why not try something like:

 $('#test').change(function(){ function1(); function2(); }; 
0
source

Source: https://habr.com/ru/post/1479624/


All Articles