Activating jQuery tabs from URL #id is www.somedomain.com/index.php#tab3
Given this my best shot, and it does work but I feel it could be far far better.
Please tell me if this is totally shockingly bad JS.
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
//On Click Event
$("ul.tabs li").click(function (e) {
e.preventDefault();
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
});
if(document.location.hash!='') {
//get the index from URL hash
var tabName = window.location.hash;
$(tabName).show(); //Show tab from url hash
var tabNumber = tabName.substr(4,1); //shorten #tab2 to just last digit "2"
$("ul.tabs li:nth-child(tabNumber)").addClass("active").show();
} else {
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
}
});
Thank you