tags:

views:

234

answers:

3

Hello I am trying to get index of current selected tab. Alert(ui.index) returns "undefined". Any idea why?

thanks

    <script>
 $(document).ready(function(){
  var $tabs = $("#apttabs > ul").tabs();

  $tabs.bind('tabsselect', function(event, ui) {
   alert(ui.index);
  });
 });
</script>


<div id="apttabs">
    <ul>
     <li><a href="#fragment-1"><span>tab1</span></a></li>
     <li><a href="#fragment-2"><span>tab1</span></a></li>
     <li><a href="#fragment-3"><span>tab1</span></a></li>
        </ul>

    <div id="fragment-1">content 1</div>
    <div id="fragment-2">content 1</div>
    <div id="fragment-3">content 1</div>

</div>
A: 

index is not a defined property of the UI DOM element. Also, what event is 'tabselect'? It is not listed as a possible value in the jquery bind document.

Also, what do you want index for? You can determine that from the event target node's href (since you've given incremental hash names in each href).

Justin Johnson
Hello Justin, thanks for your answer. "tabsselect" is listed here: http://docs.jquery.com/UI/Tabs but for some reason it doesnt work like manual says.. I need to get index of selected tab when tab is changed.
Kelvin
Oh right, the UI library. I haven't used that yet so didn't think to look there.
Justin Johnson
A: 

How about

$tabs.tabs('option', 'selected') instead of ui.index?

Pawel Krakowiak
Hey Pawel, no, it doesn't work either. Returns [object Object].
Kelvin
A: 

It looks like your tabs creation code is wrong in the first place, at least it does not work for me.

It should be var $tabs = $("#apttabs").tabs() and then the ui.index works properly as well.

Pawel Krakowiak