Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for .load to finish and then do something

Tags:

jquery

I'm loading an external script through .load('url') and need to wait for it to finish so I can update the source of an image. Sometimes load is fast enough that the image reload applies, but most of the time it takes too long and the image reload happens first, so the image doesn't actually change.

like image 707
Nathan Avatar asked Sep 06 '25 03:09

Nathan


1 Answers

Add a callback function:

$('#yourElement').load('yourUrl.html', function() {
  /* When load is done */
});

More to read at http://api.jquery.com/load

like image 185
Love Dager Avatar answered Sep 07 '25 23:09

Love Dager