YUI 3.x Home -

YUI Library Examples: TabView: TabView from Existing Markup

TabView: TabView from Existing Markup

This example shows how to create a TabView widget from existing HTML on the page.

foo content

bar content

baz content

Creating A TabView From Existing Markup

A TabView can be created easily from existing markup, supporting a progressive enhancement approach to development.

The Markup

The only markup requirements are an unordered list of items and a corresponding group of divs.

  1. <div id="demo">
  2. <ul>
  3. <li><a href="#foo">foo</a></li>
  4. <li><a href="#bar">bar</a></li>
  5. <li><a href="#baz">baz</a></li>
  6. </ul>
  7. <div>
  8. <div id="foo">
  9. <p>foo content</p>
  10. </div>
  11. <div id="bar">
  12. <p>bar content</p>
  13. </div>
  14. <div id="baz">
  15. <p>baz content</p>
  16. </div>
  17. </div>
  18. </div>
<div id="demo">
    <ul>
        <li><a href="#foo">foo</a></li>
        <li><a href="#bar">bar</a></li>
        <li><a href="#baz">baz</a></li>
    </ul>
    <div>
        <div id="foo">
            <p>foo content</p>
        </div>
        <div id="bar">
            <p>bar content</p>
        </div>
        <div id="baz">
            <p>baz content</p>
        </div>
    </div>
</div>

The JavaScript

TabView extends Widget, and the srcNode becomes the contentBox. This is the minimal requirement to create a Tabview instance for the markup, and can be assigned using a selector. Calling render enlivens the TabView making it usable.

  1. var tabview = new Y.TabView({srcNode:'#demo'});
  2. tabview.render();
    var tabview = new Y.TabView({srcNode:'#demo'});
    tabview.render();

Copyright © 2010 Yahoo! Inc. All rights reserved.

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