I have a div navigation, inside this div is a div login. I use javascript that displays divs login_name_field, login_pw_field, register_btn, do_login_btn, hide_login and hides the div login when I click the login div.
The hide_login div, when clicked hides all the newly displayed divs including itself and displays the original login div. It all works like a charm, but I would like to have one more function that does the same as hide_login but is triggered by clicking anywhere outside the main navigation div. I tried to adjust my code, but I am getting is not defined error on the new clicked vars.
Please have a look at the code below. Thank you all for reading and in advance for the replies :) Have a nice holiday.
    $( "#login_btn" ).click(function() {
    
                        $('#login_name_field').toggle()
                        $('#login_pw_field').toggle()
                        $('#register_btn').toggle()
                        $('#login_btn').toggle()
                        $('#do_login_btn').toggle()
                        $('#hide_login').toggle()
                        var loginClicked = 1;
    });
    $( "#hide_login" ).click(function() {
    
                        $('#login_name_field').toggle()
                        $('#login_pw_field').toggle()
                        $('#register_btn').toggle()
                        $('#login_btn').toggle()
                        $('#do_login_btn').toggle()
                        $('#hide_login').toggle()
                        var loginClicked = 0;
    });
    $( "#navigation_bar" ).not().click(function() {
        if(loginClicked == 1){
            $( "#hide_login" ).click();
        }
    });    <div id="navigation_bar">
    
      <!-- DO Login BTN -> runs the login function -->              
      <div id="do_login_btn" class="do_button" style="display: none;">
        <input type="submit" id="nav_btn" name="whatever" value="Log In!">
      </div> 
                                    
      <!-- Hide Login BTN -->
        <div id="hide_login" class="hide_button" style="display: none;">
      </div>            
                                    
      <!-- Login PW field -> input for login query -->
      <div id="login_pw_field" class="button" style="display: none;">
        <div id="field_div">
          <input type="password" name="login_pw_field" value="password" class="p_reset" id="password">
        </div>
      </div>
                        
      <!-- Login NAME/Email field -> input for login query -->
      <div id="login_name_field" class="button" style="display: none;">
        <div id="field_div">
          <input type="text" class="n_reset" name="login_name_field" id="name" value="Name / Email"></input>
        </div>
      </div>
                               
      <!-- Register BTN -> forwards to Account Recovery Page -->
      <div id="acc_rec_btn" class="button" style="display: none;">
        <p id="center">Account Recovery</p>
      </div>
                                
      <!-- Login BTN -> displays Login NAME & PW fields, DO Login BTN, Register BTN -->                 
      <div id="login_btn" class="button" style="display: block;">
        <p id="center">Log In</p>
      </div>
    </div>Also it appears that the $( "#navigation_bar" ).not().click(function() only triggers when I am clicking inside the navigation_bat div instead of outside of it. I thought the not() takes care of that. Well, let me know what you think :)
