Multiple function call on html onclick

Is it possible to use the onclick HTML attribute to call more than one jQuery function

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

Here, the first function works correctly, and the second function does not work.

+5
source share
3 answers

I offer you the following 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 other ways ...

+12
source

Why don't you use jquery click () listener? Do not mix dom with jquery. Keep it simple.

 $(yourselector).click(function(){ //call some funtions }); 
+1
source
 <div id="yup">click me</div> 

Js

 $(function(){ // same as $(document).ready()... $('#yup').on('click',function(){ // call function 1 // call function 2 // call function 3 // ... }); }); 

Demo

+1
source

Source: https://habr.com/ru/post/1206934/


All Articles