YUI recommends YUI 3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This demonstrates how to build a TabView from JavaScript.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat.
It is possible to build a YUI TabView widget completely from script.
We will create a container to insert our new TabView into. This can be any existing element on the page, including the <body>
, but for this example, we will create a <div>
called container
:
1 | <div id="container"></div> |
view plain | print | ? |
First we will create a TabView instance, omitting the element
argument, which signals the constructor to create the TabView container:
1 | var tabView = new YAHOO.widget.TabView(); |
view plain | print | ? |
Next we add tabs to our TabView, including the label and content for each tab and set the default selected tab to "active":
1 | tabView.addTab( new YAHOO.widget.Tab({ |
2 | label: 'lorem', |
3 | content: '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat.</p>', |
4 | active: true |
5 | })); |
6 | |
7 | tabView.addTab( new YAHOO.widget.Tab({ |
8 | label: 'ipsum', |
9 | content: '<ul><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li></ul>' |
10 | |
11 | })); |
12 | |
13 | tabView.addTab( new YAHOO.widget.Tab({ |
14 | label: 'dolor', |
15 | content: '<form action="#"><fieldset><legend>Lorem Ipsum</legend><label for="foo"> <input id="foo" name="foo"></label><input type="submit" value="submit"></fieldset></form>' |
16 | })); |
view plain | print | ? |
All that is left is to append our new TabView to our container:
1 | tabView.appendTo('container'); |
view plain | print | ? |
This is a basic example of how to build a TabView from JavaScript.
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.
INFO 215ms (+88) 12:22:42 AM:
LogReader instance0
LogReader initialized
INFO 127ms (+1) 12:22:42 AM:
Get
Appending node: ../../../2.x/build/event-mouseenter/event-mouseenter-min.js
INFO 126ms (+0) 12:22:42 AM:
Get
attempting to load ../../../2.x/build/event-mouseenter/event-mouseenter-min.js
INFO 126ms (+36) 12:22:42 AM:
Get
_next: q0, loaded: undefined
INFO 90ms (+0) 12:22:41 AM:
example
The example has finished loading; as you interact with it, you'll see log messages appearing here.
INFO 90ms (+0) 12:22:41 AM:
Tab
attributes initialized
INFO 90ms (+0) 12:22:41 AM:
Tab
creating Tab Dom
INFO 90ms (+1) 12:22:41 AM:
Tab
attributes initialized
INFO 89ms (+1) 12:22:41 AM:
Tab
creating Tab Dom
INFO 88ms (+0) 12:22:41 AM:
Tab
attributes initialized
INFO 88ms (+2) 12:22:41 AM:
Tab
creating Tab Dom
INFO 86ms (+1) 12:22:41 AM:
TabView
attributes initialized
INFO 85ms (+85) 12:22:41 AM:
TabView
TabView Dom created
INFO 0ms (+0) 12:22:41 AM:
global
Logger initialized
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.
Copyright © 2011 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings