jQuery/javascript doesn't have AND? Dropdown menu help please.
Hey, i'm trying to write an if statement for a dropdown menu so that the dropdown box only fades out when the cursor has left both the link(that originally triggered the fadeIn) and the dropdown box.
The reason I'm doing this is because currently it sometimes flickers due to moving the cursor from the dropdown box back up to the link that triggered it.
- $("#game-link").mouseenter(
- function() {
- $("#dropdown-1").fadeIn();
- });
- $("#dropdown-1").mouseleave(
- function() {
- $("# dropdown -1").fadeOut();
- });
Above is my working code.
Below is what I was messing around with that didn't work. I also tried to just do
- $("#dropdown-1, #game-link").mouseleave(
but that is more like an OR statement instead of an AND statement so it will run the fadeOut whenever either of the two scenarios occurs, which is annoying.
- $("#game-link").mouseenter(
- function() {
- $("#dropdown-1").fadeIn();
- });
- if ( $("#dropdown-1").mouseleave() && $("#game-link").mouseleave() ) {
- function() {
- $("# dropdown -1").fadeOut();
- }
- }
I know my syntax for AND (&&) doesn't work, i couldn't find the proper one if it exists. Also, i don't know if mouseleave() returns true and false so I don't know if the conditional even works to begin with. So what i'm looking for is the proper way to accomplish what I'm trying to do.