My website features a stylish box with tabbed inline content, allowing users to navigate between different views by clicking on tab names. However, I want the tabbed content to be accessible when a user clicks on a navigation link to launch the box. For example, clicking on the news link should take them directly to the news content within the box rather than the default view.
I am wondering how I can target a specific id, such as #news within the main fancybox id #menu. How can I achieve this?
HTML
<nav class="navigation">
<ul class="nav-primary">
<li class="nav-primary-item"><a class="menu" href="#menu"><i class="ico plus-yellow">+</i> Sources</a></li>
<li class="nav-primary-item"><a class="menu" href="#menu"><i class="ico plus-yellow">+</i> Topics</a></li>
<li class="nav-primary-item"><a class="menu" href="#menu"><i class="ico plus-yellow">+</i> Geography</a></li>
</ul>
<ul class="nav-secondary">
<li class="nav-secondary-item"><a class="menu" href="#menu"><i class="ico plus-greyishblue">+</i> Tools</a></li>
<li class="nav-secondary-item"><a class="menu" href="#menu"><i class="ico plus-greyishblue">+</i> Learn</a></li>
<li class="nav-secondary-item"><a class="menu" href="#menu"><i class="ico plus-greyishblue">+</i> News</a></li>
</ul>
<div class="nav-menu" style="display: none">
<div class="nav-tabs page_tabs" id="menu">
<ul class="ui-tabs-nav" role="tablist">
<li role="tab"><a href="#sources">Sources</a></li>
<li role="tab"><a href="#topics">Topics</a></li>
<li role="tab"><a href="#geography">Geography</a></li>
<li role="tab"><a href="#tools">Tools</a></li>
<li role="tab"><a href="#learn">Learn</a></li>
<li role="tab"><a href="#news">News</a></li>
</ul>
<!--Sources and Uses-->
<div id="sources">
Content here
</div>
<!--Topics-->
<div id="topics">
Content Here
</div>
<!--Geography-->
<div id="geography">
Content Here
</div>
<!--Tools-->
<div id="tools">
Content Here
</div>
<!--Learn-->
<div id="learn">
Content Here
</div>
<!--News-->
<div id="news">
Content Here
</div>
</div>
</div>
</div>
JS
<script type="text/javascript">
$('.menu').fancybox({
type: 'inline',
scrolling: 'auto',
width: 940,
height: 'auto',
padding: 0,
autoSize: false,
tpl: {
closeBtn: '<a title="Close" class="fancybox-item fancybox-close fancyboxBtn" href="javascript:;"></a>'
},
helpers: {
overlay: {
locked: false
}
}
});
EDIT
I believe changing the hashes on click could be the solution, as it would allow me to target a specific ID by giving a class a target hash. How can I link the sources tab to #sources, topics tab to #topics, and so on?
This is my initial attempt:
$('ul.nav-primary li a').click(function(e){
event.preventDefault();
window.location.hash = '#sources'
});
EDIT 2
Is there a way to target the tab index on click so that the tab becomes active?