Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - dynamically remove head elements on click

Does anyone know if you can remove head elements on a button click and how to do it with jQuery?

I am trying to get rid of certain script tags from the html head when a button is clicked. For instance. I have 1 screen view with a slideshow controlled by an external javascript file. When I click on a button "Click to get rid of this elements JS" I want to remove the external javascript path from the HTML Head.

Any ideas. Have been at this thing for a week or so.

like image 512
ClosDesign Avatar asked Aug 31 '10 18:08

ClosDesign


1 Answers

You can add an id to a script element then remove that ID:

<script type="text/javascript" src="init.js" id="initJs" ></script>

<span id="removeScript"></span>

$('#removeScript').click(function() {
     $('#initJs').remove();
});
like image 54
HandiworkNYC.com Avatar answered Oct 03 '22 17:10

HandiworkNYC.com