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
Post a Comment