YUI recommends YUI3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This documentation is no longer maintained.
This example demonstrates how to create a multi-tiered menu using existing markup on the page.
Note: By default clicking outside of a Menu instance will hide it. Additionally, MenuItem instances without a submenu or a URL to navigate to will hide their parent Menu instance when clicked. Click the "Show Menu" button below to make the Menu instance visible if it is hidden.
The markup for a Menu control follows that of
YAHOO.widget.Module, with its
body element (<div class="bd">
) containing a list element
(<ul>
).
Each item in a Menu is represented by a list item element
(<li class="yuimenuitem">
), each of which has a
label (<a class="yuimenuitemlabel">
) that can
contain plain text or HTML.
In addition to a label, each MenuItem instance can also contain a submenu. To
add a submenu via markup, simply nest the Menu markup inside the
(<li class="yuimenuitem">
) element representing a MenuItem
instance.
To instantiate a Menu hierarchy based on existing HTML, pass the id of its corresponding root
HTML element (in this case "productsandservices") to the Menu constructor
(YAHOO.widget.Menu
) then call the render
method with no arguments.
There is no need to instantiate and render submenus; as a convenience all submenus are automatically
instantiated and rendered with the root Menu.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.
Copyright © 2013 Yahoo! Inc. All rights reserved.