Are you trying to get the index of an element that matches a certain ID?
What about this?  I'd have to see your html to test and make sure it works.

Html would be something like this:

<div id="tabcontainer">
        <div id="tab1" class="tab">
                Tab1
        </div>
        <div id="tab2" class="tab">
                Tab2
        </div>
        <div id="tab3" class="tab">
                Tab3
        </div>
</div>

Code would be something like this:

function getIndexForId(searchId){
   var index = -1 //if function returns -1, then tab wasn't found
   $("#tabcontainer .tab").each(function(){
      if ("#" + searchId == $(this).attr("id")){
         index =  $("#tabcontainer .tab").index(this);
      }
   });
   Return index
}

-----Original Message-----
From: Mauro Chojrin [mailto:[email protected]] 
Sent: Friday, December 04, 2009 9:31 AM
To: jQuery UI
Subject: [jquery-ui] Re: Get the tab index by id

Hi:

  I found a solution. It could be improved, but so far it's working,
maybe someone can find it useful:

function getIndexForId( tabsDivId, searchedId )
{
        var index = -1;
        var i = 0, els = $("#" + tabsDivId).find("a");
        var l = els.length, e;

        while ( i < l && index == -1 )
        {
                e = els[i];

                if ( "#" + searchedId == $(e).attr('href') )
                {
                        index = i;
                }
                i++;
        };

        return index;
}

Bye.

On 3 dic, 14:02, Mauro Chojrin <[email protected]> wrote:
> Hi:
>
>   I have a problem using the jquery tabs. I think it should be rather
> easy to resolve, but I just can't figure it out and couldn't find the
> answer anywhere. Here is the thing:
>
>   I have a tab display, which is loaded dinamically, this means, each
> time i press a certain button, a new tab is added to the tab
> collection, now, what I need to do is see whether the tab id to be
> added is already there.
>
>   I tried to iterate over the tabs collection, but couldn't figure how
> to do this.
>
>   Thanks!

--

You received this message because you are subscribed to the Google Groups
"jQuery UI" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jquery-ui?hl=en.




--

You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en.


Reply via email to