0

I need to show the words "register" and "login" again when you click outside the "subheader" except when you write something in the inputs... is exactly what I have to do, just click outside the subheader

$(document).ready(function() {
    $('.register').click(function() {
        $('.register').hide();
 });
});
$(document).ready(function() {
    $('.registers').hide();
});
$(document).ready(function() {
    $('.register').click(function() {
        $('.registers').show();
 });
});
.subheader {
 background: #F3F3F3;
 margin: 0 auto;
 width: 100%;
 height: 30px;

}
.register p {
 display: inline-block;
 float: right;
 color: #179B75;
 font-size: 12px;
 padding: 0;
 padding-right: 8px;
}
.register {
 display: block;
 left: 75%;
 position: fixed;
 top: 5px;
 z-index: 10005;
 height: 30px;
}
.register>p>input {
 width: 100px;
 height: 20px;
 border: 1px solid #c8c8c8;
 font-family: FuturaLight;
 text-indent: 20px;
 font-size: 12px;
 float: right;
 display: none;
 color: #179B75;
}
.register>p>input:enabled{
 cursor: text;
}
.forms {
 width: 400px;
 height: 30px;
 display:inline-block;
 float:right;
}
.registers {
 width: 400px;
 height: 30px;
 display: inline-block;
 float:right;
}
.registerformsleft {
 width: 130px;
 height: 25px;
 display: inline-block;
 position: inherit;
 float: left;
}
.registerformsright {
 width: 130px;
 height: 25px;
 display: inline-block;
 position: inherit;
 float: right;
}
.register {
 cursor:pointer;
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/>
    <title>Prueba</title>
    <link rel="stylesheet" href="css/Principal.css"/>
    <link rel="stylesheet" href="css/main.css" />
    <link rel="stylesheet" href="css/jquery.bxslider.css" />
  </head>
  <body>
    <header>
          <div class="subheader">
            <div class="register">  
              <p>Login
              </p>
               <p>|</p>
              <p>Register</p>
            </div>
            <div class="forms">
              <form class="registers" action="demo_form.asp">
                <input class="registerformsleft" type="email" name="email" value="Email" placeholder="Format: algo@gmail.com" onfocus="if (this.value=='Email') this.value='';"><br>
                <input class="registerformsright" type="password" name="Password" size="10" value="Password" onfocus="if (this.value=='Password') this.value='';"><br>
                <input class="submit" type="submit" value="Submit">
              </form>
            </div> 
          </div>
    </header>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

    <script src="js/jquery.inputs.js"></script>
   </body>
Kenny Amaro
  • 473
  • 1
  • 3
  • 14

5 Answers5

0
$(document).on('click', function(e) {
   var target = $(e.target);
   if(
      !target.hasClass('.subheader') && // Not .subheader clicked
      !target.parents('.subheader').length && // Not child of .subheader clicked
      !$('.registerformsleft').val().length && // Left input is empty
      !$('.registerformsright').val().length // Right input is empty
     ) {
       $('.registers').hide();
    }
});
unxp
  • 318
  • 2
  • 12
0

You need to change your JS to something like below:

Demo

$(document).ready(function() {
    $('.subheader').click(function() {
        $('.registers').hide();
    });

    $('.registers').hide();

    $('.register').click(function() {
        $('.registers').show();
        return false;
    });
});
Rey Libutan
  • 5,226
  • 9
  • 42
  • 73
0

We have to use blur, so we tell jquery when this input of above mentioned class loses focus, hide the div with .forms and show div with class register.

$('.registerformsright, .registerformsleft').on('blur', function() {
  $('.forms').hide();
  $('.register').show();
});
SuperBiasedMan
  • 9,814
  • 10
  • 45
  • 73
  • Please read [How do I format my posts using Markdown or HTML?](http://stackoverflow.com/help/formatting); [edit] your answer, select your code and click the code button (`{}`). – Sebastian Simon Sep 10 '15 at 06:20
  • Please add some textual explanation on why this is the answer. What are the differences between this and the code used in the Q – Kukeltje Sep 10 '15 at 09:26
  • i am new here thats why m doing this mistakes...resst answer is we have to use blur ..so what i saying is hey jquery when this input of above mentioned class loose focus hide the div with .forms and show div with class register – Deepak Sabharwal Sep 10 '15 at 09:33
0

Is that what you are looking for.

$('body').on('click', function(){
 $('.subheader form, .register').toggle();
 })
0

Please try this one:

.subheader {
  background: #F3F3F3;
  margin: 0 auto;
  width: 100%;
  height: 30px;
}
.register p {
  display: inline-block;
  float: right;
  color: #179B75;
  font-size: 12px;
  padding: 0;
  padding-right: 8px;
}
.register {
  display: block;
  left: 75%;
  position: fixed;
  top: 5px;
  z-index: 10005;
  height: 30px;
}
.register>p>input {
  width: 100px;
  height: 20px;
  border: 1px solid #c8c8c8;
  font-family: FuturaLight;
  text-indent: 20px;
  font-size: 12px;
  float: right;
  display: none;
  color: #179B75;
}
.register>p>input:enabled {
  cursor: text;
}
.forms {
  width: 400px;
  height: 30px;
  display: inline-block;
  float: right;
}
.registers {
  width: 400px;
  height: 30px;
  display: inline-block;
  float: right;
}
.registerformsleft {
  width: 130px;
  height: 25px;
  display: inline-block;
  position: inherit;
  float: left;
}
.registerformsright {
  width: 130px;
  height: 25px;
  display: inline-block;
  position: inherit;

}
.register {
  cursor: pointer;
}

Demo

Ivin Raj
  • 3,448
  • 2
  • 28
  • 65