YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Menu Family: Grouped Menu Items Using Markup

# Menu Family: Grouped Menu Items Using Markup

This example demonstrates how to group 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.

View example in new window.

- Yahoo! Mail
- Yahoo! Address Book
- Yahoo! Calendar
- Yahoo! Notepad

- Yahoo! Local
- Yahoo! Maps
- Yahoo! Travel
- Yahoo! Shopping

- Yahoo! Messenger
- Yahoo! 360
- Yahoo! Groups
- Flickr Photo Sharing

## Creating a Menu from existing markup with items organized into groups

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.

The body of a Menu instance can house many `<ul>` elements to organize related items into groups.

<div id="menuwithgroups" class="yuimenu"> <div class="bd"> <ul class="first-of-type"> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://mail.yahoo.com"> Yahoo! Mail </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://addressbook.yahoo.com"> Yahoo! Address Book </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://calendar.yahoo.com"> Yahoo! Calendar </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://notepad.yahoo.com"> Yahoo! Notepad </a> </li> </ul> <ul> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://local.yahoo.com"> Yahoo! Local </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://maps.yahoo.com"> Yahoo! Maps </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://travel.yahoo.com"> Yahoo! Travel </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://shopping.yahoo.com"> Yahoo! Shopping </a> </li> </ul> <ul> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://messenger.yahoo.com"> Yahoo! Messenger </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://360.yahoo.com"> Yahoo! 360 </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://groups.yahoo.com"> Yahoo! Groups </a> </li> <li class="yuimenuitem"> <a class="yuimenuitemlabel" href="http://www.flickr.com"> Flickr Photo Sharing </a> </li> </ul> </div> </div>

To instantiate a Menu based on existing HTML, pass the id of its corresponding HTML element (in this case "basicmenu") to the Menu constructor (`YAHOO.widget.Menu`) then call the `render` method with no arguments.

/* Instantiate a Menu: The first argument passed to the constructor is the id of the element in the page representing the Menu; the second is an object literal of configuration properties. */ var oMenu = new YAHOO.widget.Menu("menuwithgroups", { fixedcenter: true }); /* Call the "render" method with no arguments since the markup for this Menu instance is already exists in the page. */ oMenu.render();

## 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:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2010 Yahoo! Inc. All rights reserved.

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