I want to run a callback function just once, it should run if it removes all elements with a certain class, but for some reason the callback function runs times the number of elements that are removed, so thats not what i am looking for.
The code(form a plugin)
$.plugin= {
clear: function(str){
$('.msg').fadeOut(200, function(){
$(this).remove();
if(typeof str.remove == 'function'){
str.remove.call(this);
}
});
}
}
The easiest way would be to unset the function:
JAAulde might be right.
The following code calls the callback with all .msg elements:
Note that
$('.msg')is slow (especially in IE 7 and below) and should not be used without a tag.The reason is that they don’t support document.querySelectorAll (as Mike G said)