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 specific tab with this command:

$ (tabContainer) .tabs ('remove', index);

The index must contain the correct tab closing order. the problem is that I generate the tabs programmatically, so the likelihood of having the wrong index is likely.

+3
source share
3 answers

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 );
    }
}
+3
source

You may need to give an example of your HTML and JS / jQuery, but here is what you think you need.

$('ul li a').live('click', function(){ 
    var index = $(this).parent().index($(this).parent());
    alert(index); 
});
0
source

, , - . , , :

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++;
});
0

Source: https://habr.com/ru/post/1719866/


All Articles