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

python - Best design pattern for collection of objects -

go - serving up pdfs using golang -

python - django admin: changing the way a field (w/ relationship to another model) is submitted on a form so that it can be submitted multiple times -