YUI Library Home

YUI Library Examples: Menu Family: Grouped Menu Items With Titles From JavaScript

Menu Family: Grouped Menu Items With Titles From JavaScript

This example demonstrates how to title groups of MenuItem instances.

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.

Creating a Menu from JavaScript with items organized into groups with titles

To create a Menu with no pre-existing markup on the page, call the Menu constructor (YAHOO.widget.Menu) passing the id of the Menu element to be created as the first argument.

Add items to a Menu instance via the addItem, insertItem, or addItems methods.

Items can be organized into groups by creating a multi-dimensional array of YAHOO.widget.MenuItem configuration properties and passing it to the addItems method. Add a title to each group via the setItemGroupTitle method.

Finally, it is necessary to call the render method passing the id of, or reference to the element the Menu should be appended to.

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.

Menu Family Examples:

More Menu Family Resources:

Copyright © 2011 Yahoo! Inc. All rights reserved.

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