开发者

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

开发者 https://www.devze.com 2023-03-26 08:17 出处:网络
If you want to create a handler for elements with the tab class, event the elements which would be added later, you use:

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

精彩评论

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