deferred loading continiously until finish

deferred loading continiously until finish

I have created a simple plugin using jquery that loads the contents by using post request from server. All the info is defined on data-attr on div with name loader[]. It's successfully loading contents. However resulting data may contain more loading div tag. What I'm looking is way that once the first run is finished completely, check again if there are div with name=loader[], if there are any run the loop again and do it until there are no div with name=loader[] are present in body section. I tried wrapping the code in a for loop that runs twice but it's not working because loop finishes immediately.


Once the data is loaded using plugin I'm changing the name of that div to loaded so that in next runs it won't be available for reloading.

  1. $('body').find('div[name="loader[]"]').map(function(i, elem) { $(elem).loader(); });
Sudo code may look like this

  1. when(
  2.       load all the div name=loader[]
  3. )
  4. then
  5. (
  6.       check if there are any div name=loader
  7.       if yes go to when else stop
  8. )