1. Home
  2. Computing & Technology
  3. JavaScript

Double Bar Menu

4. JavaScript

Join the Discussion

Questions? Comments?

More of this Feature

Introduction HTML CSS

With the HTML and stylesheet code in place we have a single bar menu appearing across our page with a gap under it. To convert this into the double bar menu that was our original goal we need to add the JavaScript that will display the appropriate second bar when an entry in that first bar is selected. To do this save the following JavaScript code as bmenu.js.

Now all that remains is to link the JavaScript into the web page. This particular script has been written in such a way that the script needs to be called from the page after the menu has been loaded and so the following script tag needs to be included in the body of the page below where the HTML for the menu appears. Immediately before the </body> tag is probably the best place for it.

<script type="text/javascript" src="bmenu.js"></script>

Now your single menu bar should function differently than it did before you added the javaScript. Instead of each link opening a new page it should display the appropriate second level menu in the space below the first menu bar and the links on that menu should work to take you to the appropriate pages.

Introduction | HTML | CSS | JavaScript
Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.