FileEditViewHelp

DHTML Pop-Up Menu Example

This page demonstrates a method for creating DHTML pop-up menus that work in most browsers, including:

* Tested on Windows and Macintosh. Compatibility with other platforms is assumed based on common rendering engines. Please report any compatibility problems you encounter.

The source code (use the "View Source" feature of your browser) has been designed so as to expose the techniques that were used to achieve the effect. Large comment blocks appear throughout the code, explaining what everything does and why. This has had the unfortunate consequence of making the code quite lengthy, but this is intended as an instructive example rather than a practical implementation, so I think it is appropriate.

A more practical implementation would make use of JavaScript Objects to represent the menu structure and then would output the HTML dynamically. Abstracting the code in this way would make it easier to expand the script to support nested menus and other features, but the code would be nowhere near as approachable from a learning standpoint.

Known Problems

This script is relatively problem-free at the moment. There are only small cosmetic issues and limitations:

If you find anything else wrong with this script, or make any clever improvements, let me know (kevin@sitepoint.com)! And be sure to subscribe to the SitePoint Tech Times for more FREE scripts, tips, and tutorials like this one!

—Kevin Yank
Editor, The SitePoint Tech Times