This should be easy, right? Yet I can't sem to find any examples of such a functionality anywhere. The problem is that after I do a replaceWith() I want to then do something with those elements that were written to the DOM, but if I try to do something to them right after the replaceWith() call they don't exist yet so I need to be sure the replaceWith() is completely finished. I just want something like this to work:
$('#foo').replaceWith('some text', function() {
//do something else here
});
Thoughts?
You can make your own function that calls replaceWith
:
$.fn.replaceWithCallback = function(replace, callback){
var ret = $.fn.replaceWith.call(this, replace); // Call replaceWith
if(typeof callback === 'function'){
callback.call(ret); // Call your callback
}
return ret; // For chaining
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With