1
I have the following code
function nomes() {
function funcao() {
alert("teste");
}
function funcao2() {
alert("teste2");
}
}
<input class="todas" id="checkall" type="checkbox" onclick="funcao2();">
When trying to execute function 2 through checkbox the following error occurs: funcao2 is not defined
What is the correct way to call this function ?
I removed my answer because it only worked if I declared the functions differently and not the way your code is (that’s why it worked in my tests). Before I put another answer, I wanted to know what is your intention by placing one function within the other. The way it is there, these internal functions are only accessible within the object
nomes()
, even if you didnomes.funcao2
.– Pablo Almeida
Why not put all functions separately instead of within the function
nomes()
? What exactly are you trying to do?– Isac
I thought I’d better do it myself.
– Stan