Is the javaScript not part of the DOM?
- by DKinzer
Why is it that scripts can still function even after the code used to create them is removed from the DOM?
I ran into a situation where I wanted to prevent a broken script from running (@see my post).
In my attempt to come up with a solution I wrote an extension with the following line (just to see what would happen).
//doc is passed here because this script is running as a firefox extension outside
//of the document context.
$('script', doc).remove();
I assumed that this would remove all the scripts from the DOM, which it did, and that therefore no scripts would run on the page, which is not the case.
I would love to know more about what's behind this behavior.