chris
chris

Reputation: 36937

Upgrading jQuery UI from 1.8.6 to 1.10.3 tabsselect alternative?

Upgrading.. and trying to find a way of finding when a tab is selected so I can do so pre/post data rendering when the tab is selected. However I have hit a snag..

Original way of handling it

$(document).ready(function() {
    $("#storage").bind('tabsselect', function(event, ui)
    {
        if (ui.index === 1)
        {
            //run some code here
        }
        if (ui.index === 2)
        {
            //run some other code here.. 
        }
    });
});

Trying to piece something similar together from what I gather from docs and google searches..

$(document).ready(function() {
        var doTabAction = function(e, tab)
        {
            console.log(tab.newTab.index());
        }
        $("#storage").tabs({
            beforeActivate: doTabAction
        });
});

problem it seems is as of 1.9 tabsselect was removed. Changed to "active" or "beforeActive" of which doesn't appear to work for me.. or it might, but not the way I was expecting. So I am hoping someone will know this answer or can assist in helping me figure it out

Upvotes: 0

Views: 514

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

Use the activate event

$(document).ready(function () {
    $("#storage").tabs().on('tabsactivate', function (event, ui) {
        var index = ui.newTab.index();
        console.log('index', index)
        if (index == 0) {
            console.log('first')
        } else if (index == 1) {
            console.log('second')
        }
    });
});

Demo: Fiddle

Upvotes: 3

Related Questions