Jump to content

link directly to tab


toolman

Recommended Posts

Hi,

I have some jQuery tabs. I would like to be able to link to them directly, but I can't work out how to do this.

I have the following code:

 

<div class="container-outer">
  <div class="container">
    <div id="prod-tabs">
      <ul class="tabs">
        <li class="first_tab"><a href="#tab1">Tab 1</a></li>
        <li><a href="#tab2">Tab 2</a></li>
        <li><a href="#tab3">Tab 3</a></li>
      </ul>
    </div>
    <div class="tab_container">
      <div id="tab1" class="tab_content"> tab 1 </div>
      <div id="tab2" class="tab_content"> tab 2 </div>
      <div id="tab3" class="tab_content"> tab 3 </div>
    </div>
  </div>
</div>
</div>

 

 

How could I link directly to each of the tabs?

Thanks!

Link to comment
Share on other sites

You'd need to add some javascript that runs onload an inspects the URL hash value to determine which tab to open. For instance (untested):

jQuery(function($){
	var tab = location.hash;
	var $widget = $('#prod-tabs');
	$widget.find('a').each(function(idx,ele){
		if (ele.href == tab){
			$widget.tabs('load', idx);
		}
	});
});
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.