jQuery UI Tabs with Next/Previous

Tabbed areas are lovely, but when you start getting to more than 3 or 4 different tabs, they start to get a little crowded and it makes sense to provide alternative navigation of them. I think it makes sense to supply universally located Next/Previous buttons, so without even moving your cursor you can click through each of them.

View Demo Download Files

jQuery UI makes creating tabbed areas very easy, so the framework is based on that. But we are on our own as far as Next/Previous buttons. Fortunately, jQuery UI tabs do have a function-thing that can be called to switch tabs. We can bind it to text links to accomplish switching tabs:

$('#my-text-link').click(function() { // bind click event to link
    $tabs.tabs('select', 2); // switch to third tab
    return false;

But we want to do this (hopefully) as smart-ly as we can. So we want to:

  • Add the links dynamically to each panel. If a panel is added or removed, the Next/Previous buttons automatically adjust to the new flow. Plus, links won’t be there awkwardly with JavaScript disabled
  • Make sure there is no “Previous” button on the first panel
  • Make sure there is no “Next” button on the last panel

This is how I did it:

$(function() {

	var $tabs = $('#tabs').tabs();


	  var totalSize = $(".ui-tabs-panel").size() - 1;

	  if (i != totalSize) {
	      next = i + 2;
   		  $(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page »</a>");

	  if (i != 0) {
	      prev = i;
   		  $(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>« Prev Page</a>");


	$('.next-tab, .prev-tab').click(function() {
           $tabs.tabs('select', $(this).attr("rel"));
           return false;

  1. Learnphp
    June 7, 2010 at 11:14 am

    To learn php,html,javascript,ajax,mysql,jquery with advanced concepts, you can visit http://advancedphptutorial.blogspot.com

  2. Ramon Marco Navarro
    September 24, 2010 at 5:03 pm

    For the original article, please visit here: http://css-tricks.com/jquery-ui-tabs-with-nextprevious/

  3. Manoj
    October 25, 2010 at 10:19 pm

    Sorry but this is just cut and paste of CSS-tricks.com

    Most of your posts are coming from there!

    Thats bad dude..

    • October 26, 2010 at 11:04 am

      i know man. i just want to spread the knowledge of chris coyier.

  4. July 29, 2013 at 4:37 am

    Thanks for another great article. The place else may just anybody get that kind of info in such a perfect
    means of writing? I’ve a presentation next week, and I’m at the look for such

  1. January 2, 2011 at 6:04 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: