Am trying to create a tabbed interface in which the tabs can be visible via url and when clicked.
I have the following jQuery code
$(function() {
var tabContent = $('.tab-content');
var tabs = $('.stream-tabs li');
var urlHash = window.location.hash;
tabContent.not(hash).addClass('inactive');
tabs.find('[href=' + hash + ']').addClass('active-tab');
tabs.click(function() {
$(this).addClass('active-tab').siblings().removeClass('active-tab');
tabContent.hide();
var activeTab = $(this).find("a").attr("href");
$(activeTab).fadeIn();
return false;
});
});
This is my html markup
<ul class="stream-tabs">
<li><a href="#pheed-timeline">Pheed Timeline</a></li>
<li><a href="#directed-pheeds">Directed Pheeds</a></li>
<li><a href="#favourite-pheeds">Favourite Pheeds</a></li>
</ul>
<div class="tab-container">
<div id="pheed-timeline" class="tab-content active-tab">
Pheeed Timovmds
</div>
<div id="directed-pheeds" class="tab-content inactive">
Directed pheeds
</div>
<div id="favourite-pheeds" class="tab-content inactive">
favourite pheeds
</div>
</div>
When i click on the tab, nothing happens, the url just changes
What am i doing wrong
I think you’re looking for something like this:
I hope it’s not too hard to understand. But it should be helpfull for your own code.
For better understanding, here’s my HTML code: