When should you NOT use event delegation?

As a rule, you should always delegate a group of elements to your parents, but was it curious if at some point it is more expensive to use Persian, or when it is really necessary? Is delegating 10 handlers really savings, which is far superior? one hundred? 1000? At what point should I spend time figuring out how to delegate events to parent views. Since views are independent and unaware of parent views, delegation is not trivial, so it is curious that it is the performance that I get in modern browsers that does this.

+4
source share
1 answer

When you just need to perform an event operation on some parts of the elements. Then you use event delegation.

But if you want to skip the event operation on some part, you should not use event delegation.

You can stop the spread

$('form#global_search_ajax_post_form').delegate('.global-category-list li a', 'click', function(e){
     e.stopPropagation();  
});
Run code
0
source

Source: https://habr.com/ru/post/1530125/


All Articles