Hope this jquery based simple code will help to explain the issue.
html:
Javascript doesn't work that way! Once a script block is parsed, removing it from the DOM won't do anything... The only thing I can think of is a really ugly hack like this:
Then your remove function looks like: