Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will duplicate addEventListener calls create duplicate listener entries?

If I have an object that calls

addEventListener(Event.ENTER_FRAME, update);  
addEventListener(Event.ENTER_FRAME, update);

will that add 2 listeners?

like image 978
Pup Avatar asked May 04 '10 21:05

Pup


People also ask

How do I check if an event listener exists?

To check whether dynamically attached event listener exists or not with JavaScript, we can get and set the element's listener attribute. export const attachEvent = ( element: Element, eventName: string, callback: () => void ) => { if (element && eventName && element. getAttribute("listener") !== "true") { element.

Why is event listener not working?

If your event listener not working is dependent on some logic, whether it's about which element it'll listen on or if it's registered at all, the first step is to check that the listener is indeed added to the element. Using a breakpoint in the developer tools , a logpoint or console.

How does event listener work in JavaScript?

The addEventListener() is an inbuilt function in JavaScript which takes the event to listen for, and a second argument to be called whenever the described event gets fired. Any number of event handlers can be added to a single element without overwriting existing event handlers. Syntax: element.


1 Answers

Nope, they won't, so update will only be called once when the event triggers.

like image 83
quoo Avatar answered Jan 02 '23 21:01

quoo