I'm using AngularJS to dynamically create a page. I have some Tab (jquery) click handlers that were working fine on a previous, static version of the page.
The problem is, the $(.prevButton) and $(.nextButton) elements are created by AngularJS and evidently Jquery doesn't register them. I can paste the following code in the console once the page has been created, and all works fine.
How can I force jquery to "rescan" the DOM so that it registers all of these dynamically created elements? Or is there another technique to avoid this problem?
$(document).ready(function () {
$('.prevButton').click(function () {
var r = $(this).attr('tabGroup');
var e = ($('.nav-tabs[tabGroup=' + r + '] li.active').prev().find('a[data-toggle="tab"]'));
if (e.length > 0) {
e.click();
}
return false; //prevent the page from jumping around
});
$('.nextButton').click(function () {
var r = $(this).attr('tabGroup');
var f = ($('.nav-tabs[tabGroup=' + r + '] li.active').next().find('a[data-toggle="tab"]'));
if (f.length > 0) {
f.click();
}
return false; //prevent the page from jumping around
});
}
Many thanks for any tips!
tabsare a jQuery plugin, should be fairly easy to integrate as an angular directive. Not clear what the click handlers forf.click();do. All you've shown is an inefficientprev/nextsystem