how to get tab index by tab name in jquery?
how to get tab index by tab name in jquery?
i need to remove a certain tab by this command:
$(tabContainer).tabs('remove', index);
the index must contai开发者_C百科n the correct order of the tab to be closed. the problem is, i'm generating the tabs programmatically so chances of having the wrong index is likely.
I think this is what you want ("name" is the name of your tab) :
// close tab with a given name
function removeTab(name) {
var tab = $('#tabs a').filter(function(){
return $(this).text() == name;
}).parent();
var index = $( "li", $tabs ).index(tab);
if (index>=0) {
$tabs.tabs( "remove", index );
}
}
You may need to give an example of your HTML & JS/jQuery but here is what I think you need.
$('ul li a').live('click', function(){
var index = $(this).parent().index($(this).parent());
alert(index);
});
What I ended up doing is just looping through the list elements and looking for the text. May not be the most efficient way but it works:
var i = 0;
$('#yayTabs ul li').each(function() {
if($(this).children().text() === "TabText") {
$('#yayTabs').tabs("remove", i);
return false; //break out of $.each loop;
}
i++;
});
精彩评论