I'm working on a website that's implementing tabs via javascript, and I'd like to create a button that goes to the 'next' tab. I don't care if I have to hardcode in the tab IDs into the javascript or what, but regardless I'd like to be able to advance the tabs.
EDIT3: Here's a jfiddle implementation of what I have. I just want the next button to be able to advance the tabs similar to clicking on them. Thanks!
Here's the code I have for the current working tabs, without a button:
var tabContents = $(".tab_content").hide(),
tabs = $("ul.tabs li");
tabs.first().addClass("active").show();
tabContents.first().show();
tabs.click(function() {
var $this = $(this),
activeTab = $this.find('a').attr('href');
if(!$this.hasClass('active')){
$this.addClass('active').siblings().removeClass('active');
tabContents.hide().filter(activeTab).fadeIn();
}
return false;
});
So I'm trying to implement something similar to the tabs.click for a button, and here's what I've got so far:
var tabbtn = $(".tabbutton");
tabbtn.click(function() {
var listItem = document.getElementById('tab2');
var $this = $(this),
activeTab = $this.find('a').attr('href');
tabContents.hide().filter("#tab2").fadeIn();
return false;
});
This will actually display the right tab's information, but it won't change which tab header is highlighted.
Anyone have any ideas? Thanks in advance for the help!
jQuery UItabs? When do you call.tabs?var listItem = document.getElementById('tab2');alert('Index: ' + $('article').index(listItem));will return 1 for the index correctly.tabson any element anywhere. I tried setting up your code in jsfiddle.net but couldn't get it to work