3

I'm using the JQuery tabs plugin.

I'd like to link content within tab 1 to take me to tab 3 instead of having to click Tab 3 to get to it. How do I do this?

@redsquare... So, i modified it based on your suggestion that way I can make all the tabs interact with each other. This change works, thanks again, so I guess I'm wondering if there's a nicer way of writing this or is this the best way?

Demo with latest changes: http://jsbin.com/etoku3/

<script type="text/javascript"> 
    $(document).ready(function() {
        var $tabs = $("#container-1").tabs();
          $('a.tab1').click(function(){$tabs.tabs('select', 0);});
          $('a.tab2').click(function(){$tabs.tabs('select', 1);});
          $('a.tab3').click(function(){$tabs.tabs('select', 2);});
          $('a.tab4').click(function(){$tabs.tabs('select', 3);});
          $('a.tab5').click(function(){$tabs.tabs('select', 4);});
    });
</script>

5 Answers 5

6

You need the Tabs select method

e.g

$('#anchor').click( function(){

  $('#tabs').tabs( "select" , 2 )

});

Demo using your markup here

Sign up to request clarification or add additional context in comments.

3 Comments

Very interesting! i updated my post to reflect what you suggested. I'm looking to really have all the tabs interact with each other from any tab not just a single tab.
by golly i think you got it! now that is some link tab swapping right there!
a second issue has cropped up, is there a way to make the tab also bring focus to the top of the page? See, in this example, jsbin.com/etoku3/11 when you scroll down and click a link, you'll notice the tab DOES switch, but it doesn't take you to the top of the page to see the TOP of the content.
1
$('#tabs').tabs({ selected: "#tabs-1" });

Comments

0

If the links are going to be a common occurrence, following design could be used:

<script lang="text/javascript">
$('.tablink').live( 'click', function(){
  $('#container-1').tabs('select', $(this).attr('rel'));
});
</script>

And in the body have following links:

<span class="tablink" rel="2">Link to tab 2</span>

or

<a href="" class="tablink" rel="2">Link to tab 2</a>

2 Comments

that will not work because the tabs widget stops the links from propagating to the body which is where live listens
also, in our cms, rel is not available for me to use within a link property.
0

A semantic solution:

$(document).ready(function() {
$('a.directTab').click( function(){
    var tabWanted = $(this).attr('rel').split('-')[1];
    $('#container-1').tabs( "select" , tabWanted);
    });
});

If you have a problem with the "click" alone event, you can use "live".

For the link, you replace the "rel" attribute by the tab wanted:

<a class="directTab" rel="fragment-3">want this text</a> to link to tab 3 

Otherwise try this Obtrusive code:

<a onclick="$('#container-1').tabs('select', 2);">want this text</a> to link to tab 3 

Comments

0
$("#your button or what uou want to clivk").live('click',function()
    {

         $('#tabs').tabs({ selected: "#tabs-1" });
    });

in this code it's pointing to tab 1. You can use #tabs-2 or #tabs-3. which tab you want to open.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.