I am binding elements to a plugin. Then, I am generating more elements through AJAX and rebinding the plugin on callback.
Will jQuery rebind the custom plugin for the previous elements? Is there a more efficient solution? Thank you for your help.
$('.class').plugin();
$.post(url, function() {
// add more .class elements.
$('.class').plug开发者_StackOverflowin(); // is this efficient?
});
Your plugin should add a class or maybe a .data cache item to elements that have already been activated by the plugin. Then inside your plugin you can ignore an element if it has already been activated.
Also another way is just to select elements from the fragment returned by the ajax call.
$('.class').plugin();
$.post(url, function(response) {
// add more .class elements.
$(response).find('.class').plugin();
});
精彩评论