Jump to content

show/hide div in nav menu


Recommended Posts

Hello, I am building a navigation bar with sub menus which appear when the main item is clicked and disappear when the user clicks elsewhere. I have read numerous posts concerning this topic but I'm not sure how to implement it. My code is as follows:



var timeout = 50;
var closetimer = 0;
var ddmenuitem = 0;

// open hidden layer
function mopen(id) {

// cancel close timer

// get new layer and show it
 ddmenuitem = document.getElementById(id);
 ddmenuitem.style.visibility = 'visible';

// close showed layer
function mclose() {
if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';

// go close timer
function mclosetime() { 
closetimer = window.setTimeout(mclose, timeout);

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
        closetimer = null;
// need to somehow close layer when click-out



    <div id="main_nav">

    <ul id="nav">

    <li class="nav"><a href="#" onclick="mopen('m1')">

    <span class="nav_parent">CONTACT US</span></a>

    <div id="m1">

 <a href="#">General Inquiries</a>  

 <a href="#">Request a Quote</a>

 <a href="#">Submit Plans</a>

 <a href="#">Submit Photos</a>





An example of this is at http://jsfiddle.net/schwiegler/t859A/21/

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.