views:

25

answers:

2

Hi I want to perform a task when I click a specific tab, let's say #tab-2. how is that done? I don't understand the documentation on the jquery site.

I know how it's done on all tabs but not just one

+3  A: 

You can do it like this, just check the tab ID:

$( ".selector" ).tabs({
   select: function(event, ui) {
     if(ui.tab.href == "#tab-2") { // or ui.panel.id == "tab-2"
       //do something...
     }
   }
});

You can see what all elements are available on the passed ui argument here, ui.tab is the selected tab link (the <a>), ui.panel is the selected tab itself (the <div>).

Nick Craver
ui.panel.does it
Dejan.S
+1  A: 

like this:

$("#tab-2").click(function() {
 //do something
});

?

Jeriko
I believe he means clicking the **tab**, as in the `<a href="#tab-2">`, not the contents on the tab, this wouldn't do that.
Nick Craver
Oh, sorry - didn't ready the question properly :) Just saw "#tab" and "select" and assumed he didn't understand selectors properly.
Jeriko