YUI Library Examples: Menu Family: Multi-tiered Menu From JavaScript

Menu Family: Multi-tiered Menu From JavaScript

This example demonstrates how to create a multi-tiered menu using nothing but JavaScript.

Note: By default clicking outside of a menu will hide it. Additionally, menu items without a submenu or a URL to navigate will hide their parent menu when clicked. Click the "Show Menu" button below to make the menu visible if it is hidden.

Creating a Menu with submenus from JavaScript

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.

Each item in a Menu can contain a submenu which is set via its "submenu" configuration property. To add a submenu to an item, set the "submenu" property to an object literal containing an "id" property that represents the id for the submenu element and "itemdata" property that references an array of YAHOO.widget.MenuItem configuration properties to be used to create the items in the submenu.

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

Copyright © 2007 Yahoo! Inc. All rights reserved.

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