views:

433

answers:

2

I am creating a web application and I want to use the Tabs widget to replicate the tab functionality you find in most web browsers. I want the user to be able: to move (sort) the tabs around, create tabs dynamically, close tabs dynamically.

The problem I find is that to close a tab you need to have its index and when considering the fact that other tabs can be opened, closed, and sorted dynamically, you need to retrieve/get the tab's index when you want to close it.

A: 

So why can't you get the index?

$('ul li a').click(function(){ 
    var index = $(this).parent().index($(this).parent());
    alert(index); 
});
Jojo
I tried this code and the alert window returned a value of "0" every time despite which tab I clicked on.
AshleyS
I fixed the problem by changing "var index = $(this).parent().index($(this).parent());" to "var index = $('ul li').index($(this).parent());". Off topic, can you do code blocks in comments?
AshleyS
you can use the ` character at the beginning and end of a comment to highlight text like a code block, but i don't think you can do the actual block inside a comment.
Jojo
A: 

You'll need to add a link inside the list item that contains the tab, for closing at least, that would be the "x out" button. If the user clicks that link and you have a jquery event handler for clicking on all the links of that class, it will know the index. Same for moving/dragging. The tricky part, I'm thinking, is if you add new tabs, what is the tab going to say? "Untitled"?

Anthony