문제

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