javascript - Does jQuery class selector event binding attach eventHandler to each instance? -


im learning jquery , when read $('.classname').bind('click',function(){}) method 1 doubt arose.

does method attach event handler each instance of classname in dom? if approach -- attaching event handler lot of instances on page overhead right?

or making use of event delegation -- say, handler bound common parent make use of e.target equalto classname , execute click event, handler bound 1 dom element?

please me understand. thanks.


one more doubt. if attach event each , every dom element overload come effect? cause load browser while execution or make dom heavy (by heavy mean, difficulty in parsing dom)?

it sure bind callback each , every 1 of elements. if have lot of elements matching selector, better use event delegation.

however, don't have manually fiddle around e.target. jquery has overloaded .on() method scenraio:

$('#parent').on('click', '.children', function (){}); 

you should attach event handler closest parent possible, least amount of elements affected event listener.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -