What is the core javascript equivelent to the jquery's remove event listener
$(element).on('remove', someFunction);
What is the core javascript equivelent to the jquery's remove event listener
$(element).on('remove', someFunction);
There is no such event as remove
, either as a DOM standard event or as a jQuery extension. Your example does nothing.
You will be able to use Mutation Observers to look for removedNodes
in the future, but browser support isn't there yet.
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!");
});