elemen.addEventListener('click',func,false);
elemen.addEventListener('click',func,false);
When elemen is clicked, will the function func be called twice, or just once?
If it is called twice, then is there a solution to check if the same event listener already exists on elemen?
In your example,
funcwill not be called twice on click, no; but keep reading for details and a "gotcha."From
addEventListenerin the spec:(My emphasis)
Here’s an example:
It’s important to note, though, that it has to be the same function, not just a function that does the same thing. That’s because it works by looking for the function on the element’s handler list, and two distinct functions — even if equivalent — aren’t the same:
For example, here I’m hooking up four separate functions to the element, all of which will get called:
That’s because on every loop iteration, a different function is created (even though the code is the same).