Reputation: 17073
Is it the process of doing the binding, or the having many things bound that's the primarily issue of binding more events than necessary?
The answer's probably both, but to what extent?
Also, I would assume that mouseover events are more expensive than click events, since they have to be checked for more frequently. Right?
Upvotes: 5
Views: 362
Reputation: 342795
The binding of events does take time, so if you bind say, a hundred or more events, user interaction with the browser will be 'uneventful' during the time spent binding all of those events.
The more event handlers on the page, the longer the event queue, the slower the UI.
@Juan nicely summarises event delegation in a single sentence in his answer, as an alternative to binding events to many child elements.
Upvotes: 2
Reputation: 92334
As far as I have noticed, the more listeners you add, the slower the UI will be. Event delegation uses less memory; instead of a listener for each child node, you have a single, smarter handler at a parent element. Less memory, less attaching and detaching handlers.
Mouseover events are not necessarily more expensive, it's not extra memory, it's just that your handler is run very often, so you need to make sure it's light code
Upvotes: 1