YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Container Family: Simple Tooltip Example

# Container Family: Simple Tooltip Example

Hover over the orange box and the link to see their Tooltips.

View example in new window.

Hover over me to see a Tooltip!

Hover over me to see a Tooltip!

## Setting up Tooltips

The Tooltip Control is an extension of Overlay that is analogous to popup tooltips within common operating systems. The standard tooltip interaction pattern involves a small overlay that is displayed when the mouse hovers over a context element for a specified amount of time. Tooltip is designed to be simple to implement with easily-accessed configuration options and visual styling handled entirely via CSS.

Tooltips are instantiated by script and are rendered (and hidden) automatically when the window's `load` event fires; unlike other controls in the Container family, no call to `render` is required with Tooltip. Tooltip introduces several specific configuration properties:

- context — Defines the context element that will trigger the Tooltip to be displayed. This property can be set using either an element id or an element reference.
- text — The Tooltip's text. If the text property is omitted, the Tooltip will try to set its own text using the context element's "title" attribute.
- showdelay — The number of milliseconds to wait before showing the Tooltip on mouse over. Defaults to 200.
- hidedelay — The number of milliseconds to wait before hiding the Tooltip on mouse out. Defaults to 250.
- autodismissdelay — The number of milliseconds to wait before automatically dismissing the Tooltip. Defaults to 5000.

In this tutorial, we'll create two Tooltips. The first will be associated with an element with an id of `ctx`, and will have its text set explicitly. The second Tooltip will be associated with a link with an id of `link`, but it will retrieve its text from the link's `title` attribute:

YAHOO.example.container.tt1 = new YAHOO.widget.Tooltip("tt1", { context:"ctx", text:"My text was set using the 'text' configuration property" }); YAHOO.example.container.tt2 = new YAHOO.widget.Tooltip("tt2", { context:"link" });

The corresponding markup for the context elements for this tutorial looks like this:

<div id="ctx">Hover over me to see a Tooltip!</div> <a id="link" href="http://www.yahoo.com/" title="Do You Yahoo?">Hover over me to see a Tooltip!</a>

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

### YUI Logger Output:

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

### Container Family Examples:

- The Module Control
- Creating and Positioning an Overlay
- Simple Tooltip Example
- One Tooltip, Many Context Elements
- Simple Panel Example
- Skinning a Panel with Custom CSS: Introduction
- Skinning a Panel with Custom CSS: Advanced
- Creating a Modal "Loading" Panel
- Creating a Resizable Panel
- Dialog Quickstart Example
- SimpleDialog Quickstart Example
- Using ContainerEffect Transitions
- Using the Overlay Manager to Manage Multiple Panels
- Implementing Container Keyboard Shortcuts with KeyListener
- Using the Button ARIA Plugin (included with examples for Button Control)
- Using the Container ARIA Plugin
- Using A Menu Button To Replace A <select> Element (included with examples for Button Control)
- Replacing the content of a Button's Menu (included with examples for Button Control)
- Example of Color Picker Built in a Dialog via JavaScript (included with examples for Color Picker Control)
- Layout inside a resizable Panel (included with examples for Layout Manager)
- Editor in a Dialog Control (included with examples for Rich Text Editor)
- Menu Buttons (included with examples for Button Control)
- Popup Calendar - Advanced (included with examples for Calendar Control)
- Showing, Hiding, and Reordering Columns. (included with examples for DataTable Control)
- Split Buttons (included with examples for Button Control)
- Simple Calendar Menu Button (included with examples for Button Control)
- Calendar Menu Button with Date on Button Face (included with examples for Button Control)
- Color Picker Button (included with examples for Button Control)
- Fixed Width Menu Button (included with examples for Button Control)
- OS-Style Programs Menu (included with examples for Menu Family)
- Application Menubar (included with examples for Menu Family)
- Slider Button (included with examples for Button Control)
- Complex Application (included with examples for Layout Manager)

### More Container Family Resources:

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

Copyright © 2009 Yahoo! Inc. All rights reserved.

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