Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    168
    Thanks
    32
    Thanked 1 Time in 1 Post

    jquery dropdown menu stops working after a few uses

    I have a page navigation set up that uses jquery for its dropdown menu and sub dropdown menu. The dropdown works fine then after a few times of hovering over it and then clicking outside and coming back to it, it stops working.

    This is the jquery:
    Code:
    $(document).ready(function() {
    	$('.menu-main li').hover(
    		function() {
    			$(this).addClass('hover');
    			$(this).children('.sub-menu').slideDown(100);
    		},
    		function() {
    			$(this).removeClass('hover');
    			$(this).children('.sub-menu').stop().slideUp(100);
    		});

    if needed, i can post the the entire html page.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    You should use .stop() with parameters. Usually you'll want to use it like .stop(true, true)
    Code:
    	$('.menu-main li').hover(
    		function() {
    			$(this).addClass('hover');
    			$(this).children('.sub-menu').stop(true, true).slideDown(100);
    		},
    		function() {
    			$(this).removeClass('hover');
    			$(this).children('.sub-menu').stop(true, true).slideUp(100);
    		});

  • Users who have thanked devnull69 for this post:

    gribbs100 (08-28-2012)

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    168
    Thanks
    32
    Thanked 1 Time in 1 Post
    I believe that fixed it! Thank you so much! Iv been going crazy trying to figure this out on my own (I'm learning jquery). Thanks for teaching me the correct approach.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •