I have been trying to go about setting my page's active tab. It is weird, cause I can manually set the active tab like the following:
<div class="tabs">
<ul class="tab-links">
<li id="t1" class="active"><a href="#tab1">TAB</a></li> //setting it here works
<li id="t2"><a href="#tab2">TAB</a></li>
<li id="t3"><a href="#tab3">TAB</a></li>
<li id="t4"><a href="#tab4">TAB</a></li>
<li id="t5"><a href="#tab5">TAB</a></li>
<li id="t6"><a href="#tab6">TAB</a></li>
</ul>
<div class="tab-content">
<div id="tab1" class="tab" style="font-family: 'Open Sans', sans-serif;">
<?php include("tab1.html"); ?>
</div>
<div id="tab2" class="tab" style="font-family: 'Open Sans', sans-serif;">
<?php include("tab2.html"); ?>
</div>
<div id="tab3" class="tab" style="font-family: 'Open Sans', sans-serif;">
<?php include("tab3.php"); ?>
</div>
<div id="tab4" class="tab" style="font-family: 'Open Sans', sans-serif;">
<?php include("tab4.php"); ?>
</div>
<div id="tab5" class="tab" style="font-family: 'Open Sans', sans-serif;">
<?php include("tab5.html"); ?>
</div>
<div id="tab6" class="tab" style="font-family: 'Open Sans', sans-serif;">
<?php include("tab6.html"); ?>
</div>
</div>
However, when I try to set it like this nothing happens:
<script language="javascript" type="text/javascript">
//setting the tabIndex to the stored value.
$(".tab-links").tabs({active: tabIndex}); //need to change this somehow
var tabIndex = parseInt(localStorage.getItem('activeTab')) + 1;
console.log("local storage value of tabIndex parseInt: " + tabIndex);
if(tabIndex != null){
console.log("I am in the if statement: " + localStorage.getItem('activeTab'));
$(document).on("click", ".tabs > ul > li:nth-child(" + tabIndex + ") a", function(e) {});
//$(".tabs").tabs({
// active: tabIndex
//});
}
//storing the last tab index before page refresh
$(document).on("click", ".tab-links a", function(e) {
$('.active').removeClass('active');
$(this).parent().addClass('active');
var curTab = $('.tab-links').find('.active')[0].id;
console.log("This is the currentTab value: " + curTab.replace ( /[^\d.]/g, '' ));
var curTabIndex = (curTab.replace ( /[^\d.]/g, '' ) - 1);
localStorage.setItem('activeTab', curTabIndex);
});
</script>
Am I missing something here? I just need to somehow set the tabIndex to become the active tab on page refresh.
.tabs()from?