Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call multiple JavaScript functions in onclick event?

Is there any way to use the onclick html attribute to call more than one JavaScript function?

like image 484
Qcom Avatar asked Oct 11 '10 23:10

Qcom


People also ask

Can we call 2 JavaScript functions onClick?

Greetings! Yes, you can call two JS Function on one onClick.

How do you call more than one function on onClick?

The first solution to perform multiple onClick events in React is to include all of your actions inside of a function and then call that single function from the onClick event handler. Let's explore how to do that in a React Component: import React from 'react'; function App() { function greeting() { console.

Can you have multiple onClick functions?

So the answer is - yes you can :) However, I'd recommend to use unobtrusive JavaScript.. mixing js with HTML is just nasty.


1 Answers

onclick="doSomething();doSomethingElse();" 

But really, you're better off not using onclick at all and attaching the event handler to the DOM node through your Javascript code. This is known as unobtrusive javascript.

like image 111
brad Avatar answered Nov 04 '22 00:11

brad