Testing UI tabs for first time for a personal project. Included what i have so far. I need to load 2 separate script which creates a div when i click Tab 2 and Tab 3. I was doing this before using jQuery getScript when i had an onclick function for some links. Can this be done is similar fashion using UI Tabs ? If so , how ?
<li><a onclick="loadTabtwo()">Tab 2</a></li>
<li><a onclick="loadTabthree()">Tab 3</a></li>
function loadTabtwo() {
$.getScript("//tab2.js");
}
function loadTabthree() {
$.getScript("//tab3.js");
}
Here is my function to activate tabs and to have current tab reload of page refresh.
jQuery(function($) {
var index = 'qpsstats-active-tab';
var dataStore = window.sessionStorage;
var oldIndex = 0;
try {
oldIndex = dataStore.getItem(index);
} catch(e) {}
$( "#tabs" ).tabs({
active: oldIndex,
activate: function(event, ui) {
var newIndex = ui.newTab.parent().children().index(ui.newTab);
try {
dataStore.setItem( index, newIndex );
} catch(e) {}
}
});
});
Here is HTML
<div id="tabs">
<ul>
<li><a href="#tabs-1">Tab 1</a></li>
<li><a href="#tabs-2">Tab 2</a></li>
<li><a href="#tabs-3">Tab 3</a></li>
</ul>
<div id="tabs-1">
<p>Tab 1 Content Here</p>
</div>
<div id="tabs-2">
Load Script 2 Here - loadTabtwo()
</div>
<div id="tabs-3">
Load Script 3 Here - loadTabthree()
</div>
</div>