How can I create a button that will scroll to the next jQuery tab. I want to have a next button within the tabs that will scroll to the next tab, sort of like a step-by-step tutorial.
How can this be done? My code so far is below.
HTML
<div id="tabs">
<ul>
<li><a href="#fragment-1"><span>One</span></a></li>
<li><a href="#fragment-2"><span>Two</span></a></li>
<li><a href="#fragment-3"><span>Three</span></a></li>
</ul>
<div id="fragment-1">
<p>First tab is active by default:</p> <a href="nexttab">Next Tab</a>
</div>
<div id="fragment-2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh</div>
<div id="fragment-3">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh</div>
</div>
JS
$(document).ready(function () {
$("#tabs").tabs();
});
I found that with UI 1.10.0 this solution no longer works, as "selected" was deprecated. The following will work in both 1.10 and earlier versions-
You can use the
selected
option to move around, like this:Just change your anchor to match, like this:
You can view a demo here
Alternatively, make each "Next Tab" link point to a specific tab and use the
select
method, like this:Then you can use a bit shorter jQuery, and move to any tab you want:
Here's a demo of this approach
Based on Nick Craver's answer, here's how I produced the same functionality using next-buttons that look like this in the HTML at the bottom within each tab div:
Based on Nick's answer I created two functions:
Since each button belongs to the "btnNext" class, after the page loads, I call:
and this enables each button's ability to move to the next tab.