Tuesday, May 8, 2012

jQuery Tabs - getting selected tab on page reload

I'm usig the jQuery Tabs funtion from jqueryfromdesigners, but only the first example works for me. That's the script-code I use:



    <script type="text/javascript" charset="utf-8">
$.noConflict();
$(function () {
var tabContainers = $('div.tabs > div');
tabContainers.hide().filter(':first').show();

$('div.tabs ul.tabNavigation a').click(function () {
tabContainers.hide();
tabContainers.filter(this.hash).show();
$('div.tabs ul.tabNavigation a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
});
</script>


And here's the demo-code for displaying the tabs:



<div class="tabs">
<!-- tabs -->
<ul class="tabNavigation">
<li><a href="#first">Send a message</a></li>
<li><a href="#second">Share a file</a></li>
<li><a href="#third">Arrange a meetup</a></li>
</ul>

<!-- tab containers -->
<div id="first">
<p>Lorem ipsum dolor sit amet.</p>
</div>
<div id="second">
<p>Sed do eiusmod tempor incididunt.</p>
</div>
<div id="third">
<p>Ut enim ad minim veniam</p>
</div>
</div>


I have already changed the code for my use. In the tab-content-divs are now displayed informations which I grab via php. This content has many links in it that reloads the page when clicked.



How can I achieve that when the user clicks on a link in #tab2 the page reloads and displays the last selected #tab2? Now it always shows #tab0...



I would appreciate any hint on this!



Cheers!





No comments:

Post a Comment