开发者

Something like jQuery live, but not for events, rather for jQuery objects

If you want to create a handler for elements with the tab class, event the elements which would be added later, you use:

$('.tab开发者_如何学Go').click(function(){
    // Doing something here.
});

Now, my question is, is there anything similar to this late-binding event handler for object selection? In other words, what if I cache the jQuery object of elements with class tab in a variable called tabs:

var tabs = $('.tab');

Now, if I add another element with class tab, it won't be added to the tabs variable. Is it anyway to get the tabs variable late-bound to the collection of objects with tab class?


You can use the live query plugin.

Live Query also has the ability to fire a function (callback) when it matches a new element

Beware of over using this however as it scans the dom every 20 milliseconds to look for changes which can degrade overall page performance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜