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

82
Views
Show wait dialog on long running change event

I have a checkbox with a change event. When there is many data, the click on the checkbox does some background task which can take some time.

So the first thing I do is:

$chxSelectAll.on('change', function (e) {
            $('.loadingnew').show()
            ... Long running code here
}

The problem is: The waiting spinner is only shown, when the change event completed the code. The code works outside or from console without problem. How can I force the show() before the code is running?

Best regards

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The waiting spinner is only shown, when the change event completed the code.

That means that the long-running task isn't in the background, it's in the foreground, tying up (blocking) the thread that's shared by the JavaScript code and the page display code.

You have two choices:

  1. If possible, offload the long-running task to a web worker thread, so it's not running on the main UI thread, blocking page updates.

  2. If that isn't possible, delay the start of the blocking code for about 60ms using setTimeout, so the browser has a chance to show the "loading" spinner before the code holds up the thread. Beware that the spinner may well not actually spin, but it will at least be visible.

Here's an example of #2:

$chxSelectAll.on('change', function (e) {
    $('.loadingnew').show()
    setTimeout(() => {
        ... Long running code here
    }, 60);
});
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!