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.

YUI Library Examples: Container Family: One Tooltip, Many Context Elements

Container Family: One Tooltip, Many Context Elements

In the example below, a single Tooltip instance is used to display tooltips for multiple context elements.

  1. For one set of links (Group A), the Tooltip text is provided by the title attribute of the link
  2. For the other set (Group B), we'll use context related events to set the text property just before the the tooltip is displayed for each link
Group A: Single Tooltip, text set using title
Group B: Single Tootip, text set using events

Setting up the Tooltip

Tooltip can be configured to reuse a single Tooltip for multiple context elements with title attributes — by default, Tooltip will autopopulate its text configuration property with the contents of its context element's title attribute. Reuse of Tooltip instances is an advisable performance enhancement strategy, especially when you have a large number of context elements that need to invoke Tooltips.

However for certain use cases, you may want to set the text of the tooltip dynamically. You can use the context based events tooltip provides, in particular the contextMouseOverEvent and contextTriggerEvent to set the shared tooltip's text directly based on the context element the tooltip is about to be displayed for. The contextMouseOverEvent can also be used to stop the Tooltip from being displayed

In this tutorial, we will dynamically create two groups of 5 links (Group A and Group B). We'll attach one Tooltip instance to the links in Group A a second Tooltip instance to the links in Group B by setting the context property to the array of link ids for that group.

Group A: For Group A we'll set the title attribute on each of the links, to drive the tooltip's text:

Group B: For Group B we won't set titles on the links, but instead use the contextTriggerEvent to set the tooltip's text directly. The context element is available as the first entry of the args array passed to the listener:

We'll also use the contextMouseOverEvent to stop the 3rd link from showing a tooltip, by returning false from the handler. We could also set the disabled property for the Tooltip, but then we'd need to re-enable it for the other context elements.

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:

More Container Family Resources:

Copyright © 2013 Yahoo! Inc. All rights reserved.

Privacy Policy - Copyright Policy - Job Openings