I have an input element
<select id="test"></select>
on change I want to call multiple functions
$('#test').change(function1, function2);
functions for now are just alerts for now
var function1 = function(){alert('a');};
var function2 = function(){alert('b');};
Only the second function is being called. I know this because of alerts and brake points. I know one way to correct this would be to call function1, and function2 from another function, but I would like to avoid that.
Yes, you can call two JS Function on one onClick. Use semicolon (';') between both the functions.
Executing multiple functions with onclick is supported across all web browsers and for most HTML elements. It is a neat and concise method of multiple functions call.
You can't 'merge' functions as you describe them there, but what you can do is have one function be redefined to call both itself and a new function (before or after the original). var xyz = function(){ console. log('xyz'); }; var abc = function(){ console.
In short, unobtrusive JavaScript is a way of writing JavaScript so that your site visitors are not shut out of your site for one of these reasons—even if your JavaScript is not working correctly for them, they should still be able to use your site, albeit at a more basic level.
I prefer not to use anonymous functions so I would create a new function and place all work inside it.
$('#test').change(onSelectChange);
var onSelectChange = function() {
function1();
function2();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With