Scripts still run after script elements removed
<p>Why do scripts still run after their tags get removed?</p>

<p>I was testing jQuery to remove style and link tags to remove CSS styles when i accidentally typed 'script' instead of 'style' for the selector. But what happened is that the scripts defined in those tags still run. Why is that?</p>

<p><a href="http://jsfiddle.net/taXNf/" rel="nofollow">here's a sample in JS</a>:</p>

<pre><code>//assume foo is defined
foo();

var scripts = Array.prototype.slice.call(document.getElementsByTagName('script')),
    current;

//remove all scripts
while (scripts.length) {
    current = scripts.pop();
    current.parentNode.removeChild(current);
}

//foo still works
foo();​
</code></pre>

<p><a href="http://jsfiddle.net/taXNf/1/" rel="nofollow">same thing with jQuery</a>:</p>

<pre><code>foo();

$('script').remove();

foo();​
</code></pre>

<p>And a side question: If they don't get removed this way, what will?</p>
