Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery UI Tabs. How would I make one of the tabs link to a URL rather than load a tab panel?

Tags:

I am using jQuery UI tabs to create a vertical tab section of a page, and want the last vertical tab to link out to a URL rather than load a tab panel.

Any suggestions for the best way to do this? I can stick another element besides an LI into the list, but would rather have the last li just behave differently.

Thanks for any help.

Here's my javascript:

  // vtabs
  $("#aboutprod-tabs").tabs(
    { fx: [{opacity:'toggle', duration:'normal'},
    {opacity:'toggle', duration:'fast'}] })
    .addClass('ui-tabs-vertical'); 

And HTML

<div id="aboutprod-tabs">
  <ul>
    <li><a href="#tabs-1">First</a></li>
    <li><a href="#tabs-2">Second</a></li>
    <li><a href="#tabs-3">3rd</a></li>
    <li class="last"><a href="/products">Learn more...</a></li>
  </ul>
  <div id="tabs-1">
    Tab panel 1
  </div>
  <div id="tabs-2">
    Tab panel 2  
  </div>
  <div id="tabs-3">
    Tab panel 3
  </div>
</div>
like image 623
Michael Avatar asked Aug 16 '10 22:08

Michael


People also ask

How do I redirect a specific tab in jQuery?

$('[href="#tabs-3"]').

How do I make the first tab active in jQuery?

removeClass('ep_s-click1'). addClass('ep_s1'); }} } }); if i use selected: 0 it will set up the first tab as active but it will now go through the if (theSelectedTab2 == 0) statement and go through adding those classes. if after the page loads i click on those tabs the script works perfect.


1 Answers

After your .tabs() call you can reverse the click behavior and href it changed, putting the href back like this:

$("li.last a").unbind('click').click(function() {
  this.href = $.data(this, 'href.tabs');​​​​
});

You can give it a try here.

Update: Using newer versions of jQuery:

There is no need to add a click handler once you unbind jQuery-UI's click handler from the link you want to change. This will work:

$("li.last a").unbind('click');
like image 157
Nick Craver Avatar answered Oct 14 '22 22:10

Nick Craver