Jquery UI tabs has an add event which is triggered immediately after a tab is added. In this example, when you click a button a new tab is added and it is selected.
I’m adding dynamic content using ajax in the following way:
var $tabs = $("#tabs").tabs({
tabTemplate: "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
add: function (event, ui){
var lastIndex = $("#tabs").tabs("length")-1;
$("#tabs").tabs("select", lastIndex);
}
});
function createTab(phpFile){
$tabs.tabs("add", phpFile, "Tab Title");
}
$("button").on('click', function (){
var url = "search.php?term=someRandomString";
createPlaySongTab(url);
});
My goal is to have the newly added content fade into the panel like so
add: function (event, ui){
$(ui.panel).hide();
var lastIndex = $("#tabs").tabs("length")-1;
$("#tabs").tabs("select", lastIndex);
$(ui.panel).fadeIn(1000);
}
Let’s say my .php looked like this
<?php sleep(1); echo 'hello world!';?>
In this case the content would not fade in at all since duration of the fade was fadeIn(1000) and the add event is triggered immediately after the tab is added, not after the .php file is done loading. How can I get the content to fade in after the content has completely loaded?
Try load event. This event should fire once content of remote tab was loaded.