Call multiple JavaScript functions in single onclick event

You might have a situation where you need to call multiple JavaScript functions in single onclick event. So in this post we are going to tackle the same situation.

There are two methods to handle this situation:

1. Call the functions by separating them by “;”. for example: onclick=”funca();funcb();”
2. Wrap all functions in a new function and call it.

First solution:

Then in HTML you can call this functions as mentioned below:

In the above example we have called two functions a() and b() by separating them “;”. This is very easy and there is no extra code in this approach.

Second solution:

Then in HTML you can call this functions as mentioned below:

In this second approach we have wrapped our functions in new function c(). You might have noticed that in this approach we have written extra code to achieving the same result.

Leave a Reply

Your email address will not be published. Required fields are marked *