javascript addEventlistener "click" not working
When attaching the function, you are executing it first, and attaching the return value undefined
to the event. Remove the parenthesis:
.addEventListener("click", addTodo, false);
When you put addTodo()
as a parameter, you are not passing the function itself. The first thing it does is execute the function and use the return value as the parameter instead.
Since functions without a return
statement implicitly result in undefined
, the original code was actually running the function, and then attaching this:
.addEventListener("click", undefined, false);