Having lots of high quality content isn't enough. Visitors must know that the content is there to be had, and it must be easily accessible. In this article, I provide you with simple, straight forward code that creates an expanding menu.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact Advertise on Bucaro TecHelp Advertise Here RSS News Feeds News Feeds

HTML5 Solutions: Essential Techniques for HTML5 Developers

Essential Techniques for HTML5 Developers

HTML5 brings the biggest changes to HTML in years. Web designers now have new techniques, from displaying video and audio natively in HTML, to creating realtime graphics on a web page without a plugin.

This book provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.

Click Here

Easy Expanding Menu Code

If you want your Web site visitors to stick around for a while, you need to provide lots of high quality content. But just having lots of high quality content isn't enough. Visitors must know that the content is there to be had, and it must be easily accessible.

The best solution is to place a complete menu on every page. But if you have a large quantity of content, your menu could get excessively long. One way to solve this problem is to provide an expanding menu. But most of the example code on the web for expanding menus is way too complicated to adapt for your own use.

In this article, I provide you with simple code that you can easily adapt to your own Web site. To keep it simple, the code will create a menu that expands only one level. Actually one level of expansion is all you should use, because going deeper causes loss of easy access to the content.

HTML Code for The Menu

The menu is constructed with an HTML table (<table> </table>). Each main menu and each submenu is coded as a row in the table (<tr> </tr>). Each submenu row contains two cells or table data elements (<td> </td>). Each main menu row contains one cell with its colspan attribute set to 2.

<tr>
  <td colspan="2"><a href="#" onClick="expandMenu(0); return false;">
  <img id="m0" border="0" src="closed.gif"">&:nbsp;Menu 0</a></td>
</tr>

Shown above is code for the first main menu item. Note that the table cell contains a link, and that the normal function of the link is disabled (by href="#" and return false;) and that instead the links onClick event is used to call a function named expandMenu, passing it the number of the menu (in this case 0, the first menu).

The link uses both an image (closed.gif) and text (Menu 0). Note the image has an id attribute which we can access with Java Script to change the image when the link is clicked. You change the text to the name of your menu item.

<tr id="sm00" style="display:none">
  <td>&:nbsp;</td>
  <td><a href="#">Submenu 0</a></td>
</tr>

Shown above is code for the first submenu item. Note that the table row has the style attribute set to display:none. This causes the table row to NOT be displayed. Note that the table row has an id attribute which we can access with Java Script to change the display style (to block to make it visible).

The first cell in the submenu row contains only a &:nbsp; (non-breaking space character code) which causes the submenu item to appear indented. The second cell in the submenu row contains a link. Replace the # in this link with the URL for your submenu item. The second cell in the submenu row also contains text (Submenu 0). You change the text to the name of your submenu item.

RSS Feed RSS Feed



Web Design Sections

Eloquent JavaScript: A Modern Introduction to Programming

Eloquent JavaScript

Eloquent JavaScript Eloquent JavaScript goes beyond the cut-and-paste scripts of the recipe books and teaches you to write code that's elegant and effective. You'll start with the basics of programming, and learn to use variables, control structures, functions, and data structures. Then you'll dive into the real JavaScript artistry: higher-order functions, closures, and object-oriented programming.

Reader Anthony says, "This book is not your typical Javascript book. Others have a utilitarian approach. In stark contrast, Eloquent JavaScript does not merely provide you a checklist of things to learn but rather paints a panorama of the possibilities that programming provides. Javascript is merely the tool used to introduce these to the reader.

Click here for more information.


[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268