Question

Ok, so this is entirely theoretical (If this WERE possible, I can see it leading to nightmarish implementation), but script tags read similar to other HTML tags. Short of causing a blackhole and destroying my computer and love ones, what would happen if I were to try and give a script tag an ID and remove it using?

$('#scriptobject').remove();
Was it helpful?

Solution

what would happen if I were to try and give a script tag an ID and remove it

Yes, you can add id attribute to your script tag -

<script id='jq' src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>

when you try to remove script tag using id #jq, that script tag will be removed from DOM

Demo

http://jsfiddle.net/medTp/1/

$(function(){
   $('#jq').remove();
   console.log($('html').html());
   $('body').append('works');
});

You can see on console, that script tag is removed,

And the next two statement's make use of $ , so you can be sure that even if the tag is removed, the script is still there in memory.

OTHER TIPS

I don't think you can give an ID to a script tag:

http://www.w3.org/TR/html-markup/script.html

But as pXL said, you can remove the script, and load a new one:

Jquery to change src of a script tag using a select value

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top