Reputation: 1058
I have a jQuery tab, and this is my code:
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("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
return false;
});
});
how i can get next and Previous links for tabs?
This is my HTML Code:
<ul class="tabs">
<li>
<a href="#tab1">Tab1</a>
</li>
<li>
<a href="#tab2">Tab2</a>
</li>
<li>
<a href="#tab3">Tab3</a>
</li>
</ul>
<div class="tab_container">
<div id="tab1" class="tab_content">Content 1</div>
<div id="tab2" class="tab_content">Content 2</div>
<div id="tab3" class="tab_content">Content 3</div>
</div>
Your post does not have much context to explain the code sections; please explain your scenario more clearly.
Upvotes: 1
Views: 778
Reputation: 1948
Here's a quick draft for a "Next" link:
$('#next').click(function() {
var activeTab = $('.tab_container div.tab_content:visible');
var nextTab = activeTab.next();
if(nextTab.length) {
activeTab.hide();
nextTab.show();
}
});
For a "Previous" link, just change next()
with prev()
(and change also the $('#next')
accordingly)
Upvotes: 2
Reputation: 18064
Refer the LIVE DEMO
I have applied CSS classes extra to your JQuery and HTML as follows:-
ul.tab li {
display: none;
}
.active {
display: block;
}
It seems working fine. Check it out once again.
Upvotes: 0