In my website i got a button. If u click it, a dropdown will come. If you click it again. It’ll disappear.
I use the jQuery function TOGGLE for it.
Now i want the following. If you move out of the dropdown for 2 seconds, or click somewhere outside the dropdown. it has to disappear again.
Is there a way to switch the Toggle function with a timer and click outside?
This is the code:
$(Ar3).addClass(aU);
$('.ContextMenuLink').toggle(function () {
$(hP).css('background', '#fff');
$('.ContextMenuTxt').css('color', '#6b8592');
$(CM).css('display', 'block');
$(Ar3).addClass(aD).removeClass(aU);
}, function () {
$(hP).css('background', 'none');
$('.ContextMenuTxt').css('color', '#fff');
$(CM).css('display', 'none');
$(Ar3).removeClass(aD).addClass(aU);
});
Just set your timer to issue a
$('.ContextMenuLink').click().As for the outside click, I would do something like this:
You should also remember to unbind this event whenever you close the drop-down by clicking on it or using the timer.