开发者

Which way is better to find and bind element with event in JQuery?

E.g:

$('.container').find('specialElement').bind('event',function(){...});

开发者_如何学Goor

$('.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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜