0

Does anyone know how to remove "js/sample.js" file from my html page when I click this p tag:

 <!DOCTYPE html>
 <html>
 <head>
<style>
p { color:red; margin:5px; cursor:pointer; }
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="js/sample.js"></script>
</head>
 <body>
<p>First Paragraph</p>
 <p>Second Paragraph</p>
 <p>Yet one more Paragraph</p>

<script>
$("p").click(function () {
$(' ').removeattr('src');

 });
 </script>
</body>
 </html>
Vektor
  • 560
  • 4
  • 15
SP182
  • 11
  • 1
  • 5
  • 4
    What do you want to accomplish here? You can't really "unload" script that's already been evaluated. http://stackoverflow.com/questions/591685/how-can-i-dynamically-unload-a-javascript-file – Chris Farmer Apr 29 '13 at 17:03

2 Answers2

5

dear friend try the following code it will work for you

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script id="script1" src="js/sample.js"></script>

<script>
    $(function () {

        $("p").click(function () {
            $('script1').att('src').remove();
        });
    });
</script>
Idrees Khan
  • 7,702
  • 18
  • 63
  • 111
Developerzzz
  • 1,123
  • 1
  • 11
  • 26
0

You can remove the script tag with

$('script[src="js/sample.js"]').remove();

however, once the script has executed, simply removing that tag will not 'undo' the script. You need to actually destroy whatever variables/methods your sample.js script has created.

sd7syfsk
  • 61
  • 2
  • https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/delete – Racheet Apr 29 '13 at 17:12
  • 1
    @Racheet delete doesn't work for variable which is not instanciate as property of window global object – A. Wolff Apr 29 '13 at 17:19
  • sorry, I used destroy when I probably should have said delete. How you go about this specifically depends on the content of sample.js itself. – sd7syfsk Apr 29 '13 at 17:21