I spent an unrealistic amount of time trying to fire a function when the tab changes of the bootstrap 3 tab/navbar and literally all suggestions google spat out wer
To add to Mosh Feu answer, if the tabs where created on the fly like in my case, you would use the following code
$(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
var tab = $(e.target);
var contentId = tab.attr("href");
//This check if the tab is active
if (tab.parent().hasClass('active')) {
console.log('the tab with the content id ' + contentId + ' is visible');
} else {
console.log('the tab with the content id ' + contentId + ' is NOT visible');
}
});
I hope this helps someone