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
    Dec 2010
    Location
    California
    Posts
    201
    Thanks
    30
    Thanked 8 Times in 8 Posts

    Need this to slide up when clicked anywhere

    Hi all,

    I have the following code, that works, but I need this thing to close when someone clicks anywhere on the page except for the div itself. Here is the code:

    Code:
    jQuery.noConflict();
    jQuery(document).ready(function(){
        jQuery('#login-trigger').click(function(){
    		jQuery(this).next('#login-content').slideToggle();
    		jQuery(this).toggleClass('active');					
    		
    		if (jQuery(this).hasClass('active')) jQuery(this).find('span').html('▲')
    			else jQuery(this).find('span').html('▼')
    		})
    
    });
    you can see it here by clicking the Login link at the top right hand corner.

    Thanks in advance,
    eberdome
    "The problem with troubleshooting is that trouble shoots back."

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
        jQuery.noConflict();
        jQuery(document).ready(function () {
            jQuery('#login-trigger').on('click', function (e) {
                var $this = jQuery(this);
                $this.next('#login-content').slideToggle();
                $this.toggleClass('active');
    
                if ($this.hasClass('active')) {
                    $this.find('span').html('▲');
                    jQuery(document).on('click.logintrigger', function(e) {
                        var $el = jQuery(e.target);
                        if ($el.closest('#login-trigger').length == 0 && $el.closest('#login-content').length == 0) {
                            $this.trigger('click', [e]);
                        }
                    });
                }
                else {
                    $this.find('span').html('▼');
                    jQuery(document).off('click.logintrigger');
                }
            });
    
        });
    Last edited by glenngv; 09-23-2013 at 11:11 PM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • Users who have thanked glenngv for this post:

    eberdome (09-25-2013)

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    California
    Posts
    201
    Thanks
    30
    Thanked 8 Times in 8 Posts
    Worked like a charm Glenn! Many Thanks!
    "The problem with troubleshooting is that trouble shoots back."


  •  

    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
    •