SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with toggle

    hello

    I have this script which is a drop down menu. When the button is clicked it toggles the menu to be displayed. When the button is clicked again it toggles the menu to be hidden.

    Code:
    $(function() {
    
        var button = $('.button');
        var menu = $('.menu');
    
        
        $('ul li a', menu).each(function() {
            $(this).append('<span />');
        });
        
        button.toggle(function(e) {
            e.preventDefault();
            menu.css({display: 'block'});
            $('.ar', this).html('▲').css({top: '3px'});
            $(this).addClass('active');
        },function() {
            menu.css({display: 'none'});
            $('.ar', this).html('▼').css({top: '5px'});
            $(this).removeClass('active');
            
        });
        
        
    
            
            
    });
    How can I make it so when the toggle menu is active, and I click on the menu or on the outside it is hidden again.
    At the moment it will only hide itself if the button is clicked on again.

    Regards

  2. #2
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps try something like

    $(".button").blur(function() {
    $(".menu").hide();
    });


Bookmarks

Posting Permissions

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