简体   繁体   中英

Is there a way to detect when a DOM node is about to be removed from the DOM?

Is there a way to detect when a DOM node is about to be removed from the DOM? ie. something like onBeforeNodeRemoved ?

I am currently using mutation observers and the node appears to have already been removed by this point.

Edit: The use-case is that an AngularJS 1.x application is being removed from the DOM by AngularJS-unaware code, and I want to detect the DOM node removal and invoke rootScope.$destroy .

If I read your question correctly, it sounds like you're saying that by the time you get your mutation observers in place, the node you are trying to watch is already removed. So you never manage to observe it.

If this is the case get your mutation observers into the page and setup before anything else at all. It's the only way I can see that you would be able to observe "everything" that happens.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM