Good day! There is a half working code, I can not understand where the error is.
$(document).ready(function(){ $('#login-trigger').click(function () { $("#login-content").toggle("slide"); }); if ($("#login-content2").is(":hidden")){ $('#signup').click(function () { $("#login-content2").toggle("slide") $("#login-content").hide(); }); } else{ $('#login-trigger').click(function () { $('#login-content2').hide(); }); } }); *{ margin: 0; padding: 0; } nav ul { margin: 0; list-style: none; position: relative; float: right; background: #2980b9; } nav li { float: left; } nav #login-trigger{ display: inline-block; zoom: 1; padding: 10px; } #signup{ display: inline-block; margin-top: 10px; color: white; } nav #login-content, #login-content2{ display: none; position: absolute; top: 0px; right: 0; z-index: 999; background: #3498db; padding: 15px; } nav li #login-content, #login-content2{ right: 46px; width: 250px; } /*--------------------*/ #login #submit { background: #2980b9; border: none; float: left; height: 30px; padding: 0; width: 100px; cursor: pointer; color: #fff; } #login #submit:hover, #login #submit:focus { background-color: #1476b7; } #login #submit:active { outline: none; } #login #submit::-moz-focus-inner { border: none; } #login label { float: right; line-height: 30px; color: white; } #login label input { position: relative; top: 2px; right: 2px; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Flyout login form</title> <link rel="stylesheet" href="style/main.css"> <link rel="stylesheet" href="style/font-awesome.min.css"> <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <nav> <ul> <li id="login"> <a id="login-trigger" href="#"> <i class="fa fa-key" aria-hidden="true"></i> </a> <div id="login-content"> <form> <fieldset id="inputs"> <input id="username" type="email" name="Email" placeholder="email" required> <input id="password" type="password" name="Password" placeholder="password" required> </fieldset> <fieldset id="actions"> <input type="submit" id="submit" value="Enter"> <label><input type="checkbox" checked="checked"> remember</label> <div style="clear:both;"></div> <a id="signup" href="#">SignUp</a> </fieldset> </form> </div> <div id="login-content2"> <form> <fieldset id="inputs"> <input id="firstname" type="text" name="firstname" placeholder="first name" required> <input id="lastname" type="text" name="lastname" placeholder="last name" required> <input id="username" type="email" name="Email" placeholder="email" required> <input id="password" type="password" name="Password" placeholder="password" required> </fieldset> <fieldset id="actions"> <input type="submit" id="submit" value="Enter"> <label><input type="checkbox" checked="checked"> remember</label> </fieldset> </form> </div> </li> </ul> </nav> <script src="script.js"></script> </body> </html> The logic of work is as follows:
Click on the top square button and the authorization form appears. If the user is not authorized - clicks registration "SignUp" The authorization form closes, a reg is opened.
And now the most important thing:
If the user changes his mind, then when clicking on the same square or in any area of the screen where there is no form, everything should be closed.
I would be very grateful for the help!