I’m adding a settings tab dynamically if some clicks my settings link on the page but I’d like to remove it once the settings tab has lost focus (meaning they clicked on another tab) The tab is being removed but it seems to go into an infinite loop calling the removeSettingsTab method. Any idea why?
$("#navMain").tabs({
select: function(event, ui) {
var selected = $("#navMain").tabs( "option", "selected" );
if (selected == 8) {
removeSettingsTab();
}
}
});
$('.settings').click(function () {
createSettingsTab();
$('#navMain').tabs('select', "tab-setting");
});
function createSettingsTab() {
$("#navMain").tabs("add","#tab-setting","Settings");
$("#tab-setting").css("display","block");
}
function removeSettingsTab() {
$('#navMain').tabs('remove', 8);
}
Bind a handler to the
showevent that checks ifIf both of these conditions hold, it can go on and call
removeSettingsTab().For example, this code works for me (with 3 tabs, last one is “settings” and it has already been added):