Reputation: 788
I have a script abc.js, which has an event handler for a button as follows:
$("button").on("click", function(e){
$("script[src='abc.js']").remove();
});
what happens when the remove on the executing script is called? Will the script be unloaded, or will it stop executing? And what happens when the script is removed from other script file?
Upvotes: 3
Views: 1459
Reputation: 68393
Will the script be unloaded, or will it stop executing?
Nope, since script tag is just a way to load the script and JS engine doesn't check/validate the presence of script tag before executing a statement.
So, presence of script
tag is not relevant once the script has been loaded to the session.
Upvotes: 8
Reputation: 110
Once you have removed the script file the handlers on it will not be called as the function will no longer exist .
Upvotes: 0