uncaught exception: Node was not found (NS_ERROR_DOM_NOT_FOUND_ERR)

uncaught exception: Node was not found (NS_ERROR_DOM_NOT_FOUND_ERR)


Hello,
I should start by saying I am fairly new to JQuery so please bear with
me, but I would like to share a scenario with you all in the hope
someone can offer some clarity.
In this example, a user requests an external JavaScript file using
jquery GET:
-------------------------------------------------------------------------------------//
START
$.ajax({ type: "GET", url: "***URL here***",
-------------------------------------------------------------------------------------//
END
The requested JavaScript file performs several dynamic scripting
functions (adding script elements to the document head) and then
deletes itself purely to clean up the page source:
-------------------------------------------------------------------------------------//
START
//Locate the current script node
var scripts = document.getElementsByTagName('script');
var currentScript = scripts[scripts.length - 1];
//Set an id of the current script node if null
currentScript.id = ((currentScript.id.length == 0 ) ?
"scriptToDelete" : currentScript.id );
//***REST OF CODE HERE
document.getElementById(currentScript.id).parentNode.removeChild
(document.getElementById(currentScript.id));
-------------------------------------------------------------------------------------//
END
In the event this file is called directly within a page (<script
src=""></script>) the DOM tree is manipulated effectively and the
'currentScript' node is deleted. However in this example, due to
maintenance code also in the JQuery library (below) this script node
is deleted twice resulting in the 'Node not found error':
line 3494 // Handle memory leak in IE
line 3495 script.onload = script.onreadystatechange = null;
line 3496 head.removeChild( script ); ***conflicting code
As the method of calling this external file isn't guaranteed (and thus
it would be beneficial to leave this maintenance code in the external
file), is it fair to assume both files (the external JS file, and the
JQuery library) should perform a last minute check of 'does the parent
node have this child node' before attempting this deletion?
Or have I missed something?
I look forward to your responses!
Thanks.