Talal
Talal

Reputation: 113

jQuery on completed updating a div possible?

my jQuery code is programatically updating the contents of a div. This takes a while, since I have much content. I need an event that tells me when the div rendering is complete. Is there such a callback? Thanks.

Upvotes: 0

Views: 33

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074268

When you update the div, for instance:

$("selector for the div").html("the updated markup");

...the next line of code doesn't run until the div has been updated. At that point, the DOM updates have been completed. Normally that's good enough. If you want to be sure that those updates have been rendered (shown to the user), you can yield back to the browser using setTimeout, like this:

// ...do the updates...
setTimeout(function() {
    // They've almost certainly been rendered.
}, 0);

The delay won't be 0ms, but it'll be very brief. That gives the browser a moment to repaint (if it needs it, which varies by browser).

Upvotes: 1

Related Questions