Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
calling another function after finishing button click function in jQuery

I want to call a function named func2 after the button click function finished its operations using jQuery. I'm using this method but doesn't work. it calls the button click function on load time.

$("#btn-click").click(function(){
  //do something
});

function func2() {
  //do something
}

    $.when( $("#btn-click").click() ).done(function() {
       func2();
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is one way to do it: You define an action for the button click. In my example I created a promise with a setTimeout() call. This could be an Ajax call or anything else (not necessarily returning a promise). As soon as the action is done or the promise fulfilled, func2 will step into action.

$("#btn-click").click(func1);

function func1(){
  console.log("func1 started...");
  $.when(new Promise(res=>
setTimeout(res,1000)))
   .then(()=>{
     console.log("func1 done.");
     func2()});
} 

function func2() {
  console.log("func2");
}
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<button id="btn-click">click</button>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!