Which way is better to find and bind element with event in JQuery?
E.g:
$('.container').find('specialElement').bind('event',function(){...});
$('.container').delegate('specialElement','event',function(){...});
So,which one is better or both of them are good?
Thank you very much!!
$('.container').delegate('specialElement','event',function(){...});
Would be better if you want the event to work for elements added to the page after load. However, keep in mind if you use delegate it is not possible to stop the propagation of other events with the event specified in the delegate function.
$('.container specialElement').bind('event',function(){...});
also works
the first on is better if the element exists for the whole duration of use the second works if you dynamically add the specialElement
精彩评论