Once loaded into memory, you can not prevent the function from being called (at least I do not know a method).
But you can create a global variable that ignores the content (or part of it) of the function. Set the variable to false
and include the content of the function within a if
by checking the status of the variable. When you call the other function, change the variable's status to true
:
var ativa = false;
function teste(){
if(!ativa){
// ... todo o conteúdo da função aqui
alert("Olá!");
}
}
function desativa(){
ativa = true;
}
<input type="button" value="Chamar função" onclick="teste()" />
<input type="button" value="desativar função" onclick="desativa()" />
In this way the function will still be called but will have no effect because it will not enter the if
within it. In your case:
$('.btn').click(function(){
ativa = true;
});
Edit
Another way is to redefine the function:
window.teste = function(){
return false;
}
Example:
function teste(){
alert("Olá!");
}
function desativa(){
window.teste = function(){
return false;
}
}
<input type="button" value="Chamar função" onclick="teste()" />
<input type="button" value="desativar função" onclick="desativa()" />