remove() tag script asynchronus non remove events in js.

remove() tag script asynchronus non remove events in js.

Regards for all.

My story is this. In a head on html5 page, there is an script tag with jquery "on click events", like this:

  1. <head>
  2.       <script src="js/jquery.min.js"></script>
  3.       <script src="js/jquery-ui.min.js"></script>
  4.       <script src='js/main.js' class="fnjq"></script>
  5. </head>

the file main.js:

  1. $(document).on('click','#btnsecc',function(event) {
  2.       alert('has press the button btnsecc');
  3. });

with a  button remove the tag script for main.js:

  1. $(document).on('click','#producto',function(event) {
  2. $('head').find('.fnjq').remove();
  3. });
the tag is removed from the DOM, and the result is:

  1. <head>
  2.       <script src="js/jquery.min.js"></script>
  3.       <script src="js/jquery-ui.min.js"></script>
  4. </head>

but the events in the file main.js continue active, for example the event click in  #btnsecc continue active, and pressed button  #btnsec active the alert message.

I want to implement a remove() in tag script, remove the tag and the events in main.js.

Really appreciate any help

Thanks in advance