HomeTutorsContact

How to Call Multiple JavaScript Functions in onClick Event?

By Gulshan Saini
Published in JavaScript
July 10, 2020
1 min read

Say we want to take two actions simultaneously on a button click. The old school way of doing the same is by calling two functions inside onClick handler separated by a semicolon or wrapping two functions inside another function.

<button id='trigger' onClick='function1(); function2();'>
  Generate Message
</button>

The above approach works, however, there is another cleaner approach using event listeners. So, instead of calling inline functions, we should use event listeners on button click.

Let’s see it in action.

Output


Tags

#javascript
Previous Article
How to iterate through NodeList using Javascript?

Related Posts

JavaScript
JavaScript get tomorrow's date
December 13, 2021
1 min
Gulshan Saini

Gulshan Saini

Fullstack Developer

Topics

Angular
JavaScript
ReactJS
Typescript
Linux

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media