Stop jQuery script

I would like to know if (and how) it is possible to stop the jQuery script on a click event.

I load it on a click like this

$("#id_button").click(function() { $.getScript("script.js"); alert ("The script is activated"); });

And I would like to stop him in the same way.

+4
source share
2 answers

I'm not sure if you are idle for this or not.

You can bind and untie the event using jquery, for example

 $("#id_button").bind("click", function(){ }); 

and for unbind

 $("#id_button").unbind("click"); 
+1
source

If it concerns the dynamic "unloading" of the js file, you can apply the Jonathan Sampson method .

In principle, "script.js" can be encapsulated in an object and "click" dynamically loaded. In the next click event, by pressing any button or event of your choice, you can set this object to null by deleting these script features.

Edit: Rebecca Murphy code show slideshow.

0
source

Source: https://habr.com/ru/post/1313603/


All Articles