I have three each loops and all three may or may not be dependent on each other depending upon page level filters selected .There are total 3 filters
if(filter1 is selected) {
//runs first $.each loop and alters some of custom attr to DOM element
}
if(filter2 is selected) {
// Checks if filter1 was selected and are there any attr changes done by it
// runs second $.each loop and alters some of custom attr to DOM element
}
filter3 .... So on
Problem is I need to know if first loop in filter1 has completed its task , then only run second filter loop so that I may get all attr changes done by filter1 perfectly.So I am trying to user Deferred object .Below is my code.
var defer = $.Deferred();
if(filter1) {
$.each()
.promise
.done(function(){
defer.resolve();
return defer.promise()
});
}
// same goes for filter2 and filter3
Now I want if filter1 is selected [execute loop and return promise] or not selected [return promise] and then go into second filter following same process.How can I achieve it , also how would I know that all 3 loops have completed its execution . Note : There are no ajax call in above process at all.