0

http://jsfiddle.net/danesoul/tSCus/2/ - Here is working example of simple JQuery UI Tabs interface.

Commented string where curent_tab is defined don't work - cause crashing tabs.

Please help me write this syntax correctly.

General idea of code: I need to have in my function MySelect()

  1. variable which keeps index of currently selected tab

  2. variable which keeps index of tab which is being selected when OnSelect event happens.

There is part of more complex solution, which is strongly need these two values for future compare.

Copy of jsfiddle JS code here:

function MySelect(event, ui){
    var clicked_tab = ui.index //new clicked tab 0-1-2 indexes
    alert(clicked_tab); 
    alert(curent_tab +' / '+ clicked_tab);     
}

$(function() {
    $('#tabs').tabs({
        //var curent_tab = ui.index; //befor new one clicked 0-1-2
        select: function(event, ui) {
            MySelect(event, ui);
        }
     });
});

1 Answer 1

1

If i understood correctly you want to get the current tab and clicked tab. Try below code,

DEMO

$(function() {
    var current_tab;
    var clicked_tab;

    $('#tabs').tabs({
        show: function(event, ui) {
            current_tab = ui.index;
        },
        select: function(event, ui) {
            clicked_tab = ui.index; //befor new one clicked
            MySelect(event, ui);
        }
    });

    function MySelect(event, ui) {
        //clicked_tab = ui.index //new clicked tab
        alert(current_tab + ' / ' + clicked_tab);
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

This works perfect, thanks a lot! But I have a question: why do you write clicked_tab = ui.index; string twice? I have commented this string outside MySelect() function and it still works the same.
@DaneSoul Actually you don't have to.. jsfiddle.net/skram/tSCus/5 Updated post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.