Why do scripts still function even after the code used to create them is removed from the DOM?
I came across a situation where I wanted to prevent a broken script ( @see my post ) from working.
In an attempt to come up with a solution, I wrote an extension with the following line (just to find out what would happen).
$('script', doc).remove();
I assumed that this would remove all scripts from the DOM, which was the case, and therefore no scripts will run on the page, which is not the case.
I would like to know more about what is behind this behavior.
source share