YUI Library Home

YUI Library Examples: TabView Control: Removing Tabs

TabView Control: Removing Tabs

This demonstrates how to dynamically remove tabs from a TabView widget.

Tab One Content

Tab Two Content

Tab Three Content

Removing Tabs from a TabView

Dynamically removing tabs from a YUI TabView widget is done with the removeTab method.

We will create a <div> called demo and include the TabView markup:

1<div id="demo" class="yui-navset"
2    <ul class="yui-nav"
3        <li><a href="#tab1"><em>Tab One Label</em></a></li> 
4        <li class="selected"><href="#tab2"><em>Tab Two Label</em></a></li> 
5        <li><a href="#tab3"><em>Tab Three Label</em></a></li> 
6    </ul>             
7    <div class="yui-content"
8        <div id="tab1"><p>Tab One Content</p></div
9        <div id="tab2"><p>Tab Two Content</p></div
10        <div id="tab3"><p>Tab Three Content</p></div
11    </div> 
12</div> 
view plain | print | ?

Next, create an instance of TabView from our demo element:

1<script type="text/javascript"
2    var tabView = new YAHOO.widget.TabView('demo'); 
3</script> 
view plain | print | ?

Next we will write a function that removes the active tab:

1<script type="text/javascript"
2    var removeTab = function() { 
3        tabView.removeTab(tabView.get('activeTab')); 
4    }; 
5</script> 
6<p>A button will be used to trigger the tab removal.  Here we create it, and assign a click listener that calls our removeTab function when the button is clicked:</p> 
7<textarea name="code" class="JScript" cols="60" rows="1"
8<script> 
9    var button = document.createElement('button'); 
10    button.innerHTML = 'remove tab'
11 
12    YAHOO.util.Event.on(button, 'click', removeTab); 
13    tabView.appendChild(button); 
14</script> 
view plain | print | ?

This is a basic example of the TabView's addTab method.

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

YUI Logger Output:

Logger Console

INFO 2011ms (+1629) 1:33:24 AM:

LogReader instance0

LogReader initialized

INFO 382ms (+1) 1:33:22 AM:

example

The example has finished loading; as you interact with it, you'll see log messages appearing here.

INFO 381ms (+1) 1:33:22 AM:

Tab

attributes initialized

INFO 380ms (+1) 1:33:22 AM:

Tab

attributes initialized

INFO 379ms (+1) 1:33:22 AM:

Tab

attributes initialized

INFO 378ms (+378) 1:33:22 AM:

TabView

attributes initialized

INFO 0ms (+0) 1:33:22 AM:

global

Logger initialized

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

More TabView Control Resources:

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings