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?
Gulshan Saini

Gulshan Saini

Fullstack Developer

Subscribe to our newsletter!

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

Topics

CSS
Gatsby
Browser
HTML
JavaScript
NextJS
Puppeteer
NodeJS
Python
ReactJS
Typescript
VSCode

Related Posts

How to check if a string contains a substring in JavaScript?
January 05, 2021
1 min
© 2021, All Rights Reserved.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media