Reputation: 3162
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?
Upvotes: 0
Views: 2118
Reputation: 3348
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
Upvotes: 2
Reputation: 2964
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..
Upvotes: 1