Вопрос

I'm looping through the Jquery tabs to see if a tab with a specific name exists. If it does, I need to get it's index. I'm able to identify if it exists, but can't seem to get the correct index. Here's the code:

        var exists = false;
        $(".ui-tabs-anchor").each(function(index){
            if ($(this).text() == stock){
                exists = true;  
                var index = $(this).index();  <---- problem here
                $("#tabs").tabs({active: index});
            }
        });

I've labeled what I think the problem is. I've tried, ui.index, ui.newTab.index, etc.. Can someone help me to see what I'm doing wrong as well as how to look up where to find it? Looking through the API I keep missing it for some reason. Thanks!

Это было полезно?

Решение

Avoid that line index is already passed through callback function ,

var exists = false;
$(".ui-tabs-anchor").each(function(index){
    if ($(this).text() == "stock"){
        exists = true; 
        $("#tabs").tabs({active: index});
    }
});

If you want the index of the current item then use $(".ui-tabs-anchor").index(this)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top