Re: multiple identical addEventListeners added multiple times?
Mounir Lamouri <[email protected]> Fri, 30 Nov 2012 10:06:28 +0000
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
On 29/11/12 20:06, alta88[nntp] wrote:
>
> Adding something like
>
> x = document.getElementById("toolbar-menubar");
> x.addEventListener("click", function(event) {
> alert(event.button+":"+this.id); }, false);
>
> multiple times (Fx17, using something like ExecuteJS), say executing it
> 4 times, will result in 4 alerts when the Fx menubar is clicked.
You see this behaviour because you are using anonymous functions.
If you do this, it will work as expected:
function clickHandler(e, id) {
alert(e.button + ":" + id);
}
x = document.getElementById("toolbar-menubar");
x.addEventListener("click", clickHandler);
Note that the behaviour you are complaining about is the same in all
browsers I have been able to test.
Cheers,
--
Mounir