Clean up dynamically loaded scripts
<p>I'm working on a dynamic web app and I ran across the following issue:</p>

<p>Basically I have a single dynamic page managed by javascript, whose <code>&lt;div class="content"&gt;&lt;/div&gt;</code> is repopulated each time a user clicks a link in the navigation bar (dynamic load, no page change). The content that goes inside the <code>div</code> is a variable HTML chunk obtained from the backend (through a master servlet), based on the user's privileges.</p>

<p>This generated content also includes several <code>script</code> tags which manage that content (i.e populate the initially empty elements with data from the server). They do not contain actual code, only references to .js files.</p>

<p>The HTML is loaded inside the <code>div</code> through jQuery's <code>load</code> function, which executes the referenced scripts automatically.</p>

<p>The problem arose when I wanted to debug one of the active scripts with Firebug, I noticed that all the scripts listed in the debugger (apart from the ones I declared on the master page) were listed as a simple number (e.g 10, 5, 33, etc), instead of their actual name, and that many of them were duplicates executing simultaneously, possibly from a previous page access.</p>

<p>Is there any way I can clean up these obsolete scripts when I change the content? Possibly reference them at load time to be able to stop them?</p>
