Devajit Sonowal
Devajit Sonowal

Reputation: 11

YUI3 Tabview How to determine the label of selected tab

I need a YUI3 tabview like

<div id="demo"></div>
<script>
YUI().use('tabview', function(Y) {
    var tabview = new Y.TabView({
        children: [{
            label: 'foo',
            content: '<p>foo content</p>'
        }, {
            label: 'bar',
            content: '<p>bar content</p>'
        }, {
            label: 'baz',
            content: '<p>baz content</p>'
       }]
    });
    tabview.render('#demo');
});
</script>

Now need a event handler which will be of following specification

  1. It will be fired when user will click on tab something like "selectedTabChanged"
  2. Inside the handler will determine the label of the "SelectedTab"

Upvotes: 1

Views: 1824

Answers (1)

mjhm
mjhm

Reputation: 16705

Just add this below tabview.render('#demo');

tabview.on('selectionChange', function (e) {
    alert('Changing tab from "' + e.prevVal.get('label') + '" to "' + e.newVal.get('label') + '"');
}

Upvotes: 4

Related Questions