The Best Way To Add Eventlistener To An Element
I'm trying to find the most productive way to hanging event. Lets imagine we have this structure:
- 1st li ...
- 99999th li <
Solution 1:
I wouldn't look at "big sites" for the best web development practices. The first way has really no advantages over the other two, as it mixes JavaScript with HTML and is harder to maintain.
Event delegation will be lighter than the other two and will have the advantage of being able to handle dynamically generated elements, so in this case, it'd probably be the best choice. I would profile your application with both approaches before choosing.
Solution 2:
you can find your answer here- jQuery.click() vs onClick ,
As you can see http://jsperf.com/testper test, event delegation approach is the best approach for event hanging.In your case where you have 10000 or more events than surely 3rd approach is best for you.
Baca Juga
- Jquery & Html Data Attribute Manipulation, Really Trying To Modify / Append A New Value To Already Added Value
- Jquery Hover Not Triggered When Element Is Programatically Moved Under The Mouse
- Difference In Performance Between Calling .localecompare On String Objects And Constructing A Purpose-made Intl.collator Object?
Post a Comment for "The Best Way To Add Eventlistener To An Element"