Reputation: 11010
I have a jquery statement as follows:
$('.panel.col2, .panel.col3').fadeOut('fast', function(){
//SOME CODE
});
The problem is that these elements do not always exist, and I need it to execute the callback regardless of the success of the statement the callback belongs to. Is there any workaround to this?
Upvotes: 0
Views: 161
Reputation: 2055
Try something like this:
function myCallback(){
//SOME CODE
}
if($('.panel.col2, .panel.col3').length>0){
$('.panel.col2, .panel.col3').fadeOut('fast', function(){
myCallback();
});
} else {
myCallback();
}
Upvotes: 1
Reputation: 86892
It sounds like you want some code to run in the call back for fadeOut
and outside if their are no elements to fade out. Here is an idea but I do not know the context of what you are trying to do.
$(document).ready (function () {
var panelElement = $('.panel.col2, .panel.col3');
var fadeOutCallBack = function(){
//SOME CODE
};
panelElement.fadeOut('fast', fadeOutCallBack);
if (panelElement.length == 0) {
fadeOutCallBack();
}
});
Upvotes: 1