JavaScript performance benchmark in handling events at parent for all child elements -


It is common for parents to handle incidents for child elements in the bubbling stage on the node. However, I'm not sure there is any display problem in it. For example, consider the following structure:

  & lt; Div id = "parent" & gt; & Lt; Div & gt; Child1 & lt; / Div & gt; & Lt; Div & gt; Child2 & lt; / Div & gt; & Lt; Div & gt; Child3 & lt; / Div & gt; & Lt; / Div & gt;  

Now if I want to handle onclick on every child, I can attach every child div or just one handler to the headliner because the event is going to be bubble is .

So what was the best practice if you were curious? Are there any performance concerns in two perspectives?

If you have a large number of children, then I would recommend to go for you.

With experience, I can tell you by adding performance handlers, memory leaks and browser locks (mainly IE), by adding event handlers to the number of very large elements.

The event delegation is a very simple, light and good option in those examples.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -