jquery - Best practice for event handling with JavaScript -


what's best practice event handler? i'm unsure if should put buttons function trigger or if should, jquery, wait button's on click event.

usually can this:

$('.buttonok').on('click', function(){     alert('ok'); }); 

or add on button javascript:buttonaction().

which should prefer?

short answer: first way. event delegation way more performant, requires conditionals in code, it's complexity versus performance tradeoff.

longer answer: small number of elements, adding individual event handlers works fine. however, add more , more event handlers, browser's performance begins degrade. reason listening events memory intensive.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -