What is the core javascript equivelent to the jquery's remove event listener
$(element).on('remove', someFunction);
Here's how to do it with a Mutation Observer:
function onElementRemoved(element, callback) {
new MutationObserver(function(mutations) {
if(!document.body.contains(element)) {
callback();
this.disconnect();
}
}).observe(element.parentElement, {childList: true});
}
// Example usage:
onElementRemoved(yourElement, function() {
console.log("yourElement was removed!");
});
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