Lets say I have two javascript/jquery files. file1.js and file2.js. I want to switch between these two files with checkbox selection as I need. Something like;
If you do need to use checkboxes (e.g. to be able to un-select a chosen option), that could be done like this (using jQuery as per your topic tag):
var checkboxes = $('.selector')
checkboxes.on('change', function (event) {
var current = event.target
checkboxes.each(function () {
this.disabled = current.checked && this !== current
})
})
I’m… not… sure that @m3g4p0p 's answer actually drives to the point of the OP.
The flat answer is that the .js files would have to be coded in such a way as to be reading the input to see whether its active or not, or else implementing its methods in object-oriented design pattern and then overwriting the object repeatedly. Javascript doesn’t strictly support ‘unloading’ of functions/code.
Ah yes thanks, I misread the question as how to disable the checkbox, not the JS… so no, you can’t simply disable a certain script once it is loaded. The scripts in question would have to expose means to disable themselves (e.g. if one script adds event listeners to the DOM, it might expose a destroy() function that removes those event listeners and tidies everything up).