Reputation: 19
I need to remove two <script>
tags from a page dynamically, at the document ready
.
Every tag has its own id;
I've tried to insert in the code:
$("#idPrimoScript").remove();
$("#idSecondoScript").remove();
but nothing happens...
Some ideas? Thanks
Upvotes: 1
Views: 158
Reputation: 40038
Apparently (having not tried this myself beyond a simple proof script) the way to do this is to create another function with the same name.
See:
How to override a function in another javascript file?
JavaScript: Overriding alert()
Overriding a function in jQuery plugin
Upvotes: 0
Reputation: 9242
As I can understand from your question, you want to remove (actually disable) the scripts included in your 2 script tags. a work around I usually used to make in these situations is to introduce a variable which will act as a flag or a passing signal. let's say that I will create a global variable which will be the flage I will be using:
var enableMySpecialScript = true
as you can see, I initially set the value of this flag to true, and whenever I need to disable the special script inside my page, I set this flag to false, then inside my script file, i always check for the flag's value,so when it's only "true", the script will execute, meaning that when it's false the script will not run, which is exactly what you are asking for.
This way you don't have to mess up with removing stuff or altering functions, and from my experience with this solution, it's a clean and debuggable one :)
Upvotes: 1