0
The function addEventListener
expects two parameters - the event you want to listen to, and the function that should be executed when it is fired - the first you passed correctly, the second, not. When you do teste()
, you are calling the function (calling it). In this case, what you want to do is pass the function itself instead.
button.addEventListener('click', test)
Now, we are passing the function as argument, and it will only be called when the event is triggered.
Welcome to [en.so]! You have posted an image of the code and/or error message. Although it sounds like a good idea, it’s not! One of the reasons is that if someone wants to answer the question, they can’t copy the code and change something inside. Click on the [Edit] link and put the code/error as text. See more about this in these links - Manual on how NOT to ask questions, Post Error Message as Picture
– Icaro Martins
About your problem, note that in this code snippet
btn.addEventListener('click', teste() )
you are running the functionteste()
and passing as parameter the return of it, that is , null– Icaro Martins