Should all jquery events be bound to $(document)?
问题 Where this is coming from When I first learned jQuery, I normally attached events like this: $(\'.my-widget a\').click(function() { $(this).toggleClass(\'active\'); }); After learning more about selector speed and event delegation, I read in several places that \"jQuery event delegation will make your code faster.\" So I started to write code like this: $(\'.my-widget\').on(\'click\',\'a\',function() { $(this).toggleClass(\'active\'); }); This was also the recommended way to replicate the