Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple function call on html onclick [duplicate]

Is there any possibilities to use the onclick HTML attribute to call more than one jQuery functions

onclick="$('#editParentDetailsViews').removeClass('tab selected');$('#editStudentDetailsPopupPnl').hide(); return false;"

Here, the first function work properly and the 2nd function not working.

like image 452
Prasanth A R Avatar asked Nov 15 '14 08:11

Prasanth A R


People also ask

Can we call 2 functions in onClick?

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 two onClick events HTML?

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


1 Answers

I suggest you these ways:

1-addEventListener:

   document.getElementById('btn').addEventListener('click', function(){
    function1();
    function2();
   });

2-inline (onclick)

onClick="function1();function2();"

3-Jquery Standard click function:

 $("button").click(function(){
    //Your functions code here
});

4-Jquery on:

 $('#button').on('click',function(){
   //Your code here
 })

You can find more ways...

like image 129
Mohammad Kermani Avatar answered Nov 15 '22 06:11

Mohammad Kermani