I need to run 2 functions. The 2nd one must wait for the 1st one to complete otherwise things get messed up. My Code is below:
I have researched using jQuery.when()
and using .then
and .done
but each time I try it locally I don't get it to work right as I am honestly not understanding the documentation correctly.
I have also tried to follow other questions on here which use callbacks
in the function to achieve this. Again their code is slightly different and more Ajax based so hard for me to follow exactly.
I have not included my attempts of the above in the code below as it will like like a mess and will confuse. Thought it was best for question purpose clarity to show my original code with the 2 functions.
Thanks in Advance for any support...
var reportFilter = $.cookie("filter");
if (reportFilter == 'true') {
// function 1 - Run First
$('table tbody tr').each(function () {
var hours = $(this).find('.time').text();
if (hours == '0') {
$(this).addClass('hidden');
}
});
// function 2 - Run After Function 1 is complete
$('table tbody tr').each(function () {
var nextTR = $(this).next();
if (nextTR.hasClass('hidden') && (nextTR.hasClass('odd') || nextTR.hasClass('even'))) {
$(this).addClass('hidden');
}
});
}