0

I have this code for a Dropdown menu:

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function() {
   $('#mainnavigation > li').bind('mouseover', jsddm_open)
   $('#mainnavigation > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

and I want to modify it so the drop down will open on "Click", not on "Mouseover" and to close on "Mouseout". I've tried to use this:

$('#mainnavigation > li').bind('click', jsddm_open)

but it's not working.

Someone can help me?

1
  • 1
    Show your html with your "dropdown" Commented Apr 26, 2011 at 12:18

2 Answers 2

2

First, some HTML would help.

Apart from that, I think your function works but clicking the <li> also triggers document.onclick = jsddm_close; So your menu opens and closes right away.

Try to get rid of the document.onclick line and see if it works better

You also need a return false; at the end of your jsddm_open() function

Sign up to request clarification or add additional context in comments.

Comments

1

Can you try this?

 $('#mainnavigation > li').click(function() {
        jsddm_open();
 });

Anyway I think you are missing the " () " behind the methods, but It might just be that the syntax is new to me..

1 Comment

Used this and it doesn't work. The weird thing is that I used an "alert('test')" after "jsddm_open()" and the alert works. "jsddm_open()" function doesn't...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.