I wrote a code that whould change a li's class to active and show the correct content on click but I also would like to be able to link a visitor to example: www.socal.nu/index.php#tab2 to activate tab2.
Code:
$(document).ready(function() {
//Default Action
$(".tab_content").hide();
$("ul.tabs li:first").addClass("active").show();
$(".tab_content:first").show();
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active");
$(this).addClass("active");
$(".tab_content").hide();
var activeTab = $(this).find("a").attr("href");
$(activeTab).fadeIn();
return false;
});
});
Edited to include the (x)html structure of the tabs list (as posted by the OP in a comment to @slightlymore's answer):
<ul class="tabs">
<li><a href="#tab1">Hem</a></li>
<li><a href="#tab2">Projekt</a></li>
<li><a href="#tab3">Om SOCAL</a></li>
<li><a href="#tab4">Kontakt</a></li>
</ul>