problem with accessing a website input area

Upon clicking outside the "subheader", I need to display the words "register" and "login" again, unless something is typed into the input fields... that's all there is to it, 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: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="67060b000827000a060e0b4904080a">[email protected]</a>" 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>

Answer №1

To modify your JavaScript, consider the following code snippet:

See Demo

$(document).ready(function() {
    $('.subheader').click(function() {
        $('.dropdown-menu').hide();
    });

    $('.dropdown-menu').hide();

    $('.dropdown-trigger').click(function() {
        $('.dropdown-menu').show();
        return false;
    });
});

Answer №2

Is this the information you seek?

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

Answer №3

Here is a new code snippet for you:

.header {
  background: #F3F3F3;
  margin: 0 auto;
  width: 100%;
  height: 30px;
}
.signup p {
  display: inline-block;
  float: right;
  color: #179B75;
  font-size: 12px;
  padding: 0;
  padding-right: 8px;
}
.signup {
  display: block;
  left: 75%;
  position: fixed;
  top: 5px;
  z-index: 10005;
  height: 30px;
}
.signup>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;
}
.signup>p>input:enabled {
  cursor: text;
}
.forms-section {
  width: 400px;
  height: 30px;
  display: inline-block;
  float: right;
}
.registration-forms {
  width: 400px;
  height: 30px;
  display: inline-block;
  float: right;
}
.left-registration {
  width: 130px;
  height: 25px;
  display: inline-block;
  position: inherit;
  float: left;
}
.right-registration {
  width: 130px;
  height: 25px;
  display: inline-block;
  position: inherit;

}
.signup {
  cursor: pointer;
}

See the Demo here

Answer №4

$(document).on('click', function(e) {
   var clickedElement = $(e.target);
   if(
      !clickedElement.hasClass('.subheader') && // Clicked element is not .subheader
      !clickedElement.parents('.subheader').length && // Clicked element is not a child of .subheader
      !$('.registerformsleft').val().length && // Value of left input is empty
      !$('.registerformsright').val().length // Value of right input is empty
     ) {
       $('.registers').hide();
    }
});

Answer №5

In order to hide the div with the class .forms and show the div with the class register when an input of the specified class loses focus, we must utilize the blur function in jQuery.

$('.registerformsright, .registerformsleft').on('blur', function() {
  $('.forms').hide();
  $('.register').show();
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Flipped the dimensions of an image for better responsiveness

Trying to implement this particular design on a responsive website. Wondering if there's a way to establish an inverse resizing technique using jQuery / Javascript so that as the viewport shrinks, the text size increases. Attempted to use jQuery to a ...

Best practices for working with Angular, Laravel 4, and managing MySQL databases

I have recently started working with Angular and have some experience using Laravel 4. I am currently developing an application that allows users to edit on the go while also saving to a MySQL database. Originally, my plan was to use Angular for real-time ...

Adjustable TextBox (multiline input field)

In need of some assistance, I am working with a MultiLine asp:Textbox (similar to a standard html textarea) that I would like to have auto-sized to fit its content using only CSS. My goal is to have it display at a specified height in the web browser, with ...

How do I retrieve child nodes' properties in JavaScript?

I am currently working on a link extractor using CasperJS, and the core function looks something like this: function extractLinks() { return Array.prototype.map.call(document.querySelectorAll('a'), function(e){ return { ...

How does Angular5 perform with Bootstrap4?

Currently working on an Angular5 application and considering integrating bootstrap into it. I imported Bootstrap4, which includes dependencies on JQuery and Popper.js. Another option I came across is utilizing CSS grid for more versatility compared to boo ...

Dealing with the percentage sign in table names during data retrieval

When using React and Express to retrieve and store data in JSON format, what is the correct way to reference tables that have a percentage sign in their name? componentDidMount() { // Retrieve data from http://localhost:5000/citystats, sort by ID, t ...

How can I adjust height without affecting weight in CSS using curly brackets?

Can CSS be used to specifically adjust the height of a curly bracket without changing its thickness? I have been attempting to modify the height of a curly bracket dynamically by adjusting the font-size, but this also alters the weight. Is there a workar ...

There was an error in calculating the Foundation 5 - 1170 grid

Currently, I am in the process of learning Foundation 5 and working on an app that utilizes a 1170 grid system. The app has 70px columns and 30px gutters (which equals to 1170 when calculated as 70 * 12 + 30 * 11). However, after setting the default values ...

What defines a suitable application of the ref feature in React?

How can the ref attribute be effectively used in React? I understand that it is considered a shortcut that may go against the principles of React DOM, but I want to know the specifics of how and why. I'm currently evaluating if my use case justifies t ...

Unable to execute multiple instances of Selenium PhantomJS concurrently

I have encountered an issue while using Selenium's node.js API to run PhantomJS instances against a series of web pages. The code that I have written to perform actions on the pages is functioning correctly, but it appears that only one instance of Se ...

Sign up for our Joomla website by completing the registration form and agreeing to our terms and conditions

I am currently working with Joomla 1.5 and I need to incorporate a checkbox for users to agree to the terms and conditions. I attempted to use the code below, but it is not functioning as expected. Even when the checkbox is ticked, it still triggers an a ...

Using node modules within an HTML document

I'm finding it challenging to understand how npm handles dependencies when it comes to referencing them in HTML. For example, if I have a specific version of a plugin installed that includes the version number in its path or file name, and npm is set ...

The function message.react in Discord.js is throwing an error

I have a Discord bot set up for reaction roles. I use IDs to cache the messages that need reactions and make sure the bot reacts with the appropriate emojis before further action. Here is my process for caching the messages: const guild = await client.guil ...

Switching the background color of alternating divs in reverse order: a step-by-step guide

I am looking to alternate the background color of divs between odd and even, with the last div being grey and the second to last div being green. I have tried using the odd/even classes in CSS, but it did not work as expected. .main{ width:500px; height ...

Struggling to modify a string within my React component when the state is updated

Having a string representing my file name passed to the react-csv CSVLink<> component, I initially define it as "my-data.csv". When trying to update it with data from an axios request, I realize I may not fully understand how these react components w ...

Is there a way to cancel an AJAX request during the ajaxStart or ajaxSend event in jQuery?

In my project, I have implemented numerous $.post methods and now I need to check the session in each request to handle my page based on session value. However, I don't want to modify all the existing methods ($.post). Instead, I would like to check t ...

The identifier 'name' is not found in the specified data type

How can I resolve the error 'Property 'name' does not exist on type' in TypeScript? Here is the code block : **Environment.prod.ts** export const environment = { production: true, name:"(Production)", apiUrl: 'https://tes ...

Image link in HTML / CSS not functional on one half of the image

My webpage has an image thumbnail with accompanying text positioned to the right. I have a hyperlink on the image that should open the full-size version when clicked. However, there seems to be an issue where the hyper link only activates on the lower hal ...

Ensuring typescript req.user in Passport JS is always defined: Best practices

When utilizing Passport JS, the req.user within the route is considered potentially undefined. However, the middleware prior to my route method ensures that this scenario does not occur. How can I convey this information to TypeScript? Object may be &apos ...

Using @media queries for mobile and desktop: preventing desktop from displaying mobile styles

I have been working on redesigning a website for mobile using only CSS. I set up media queries to deliver the appropriate CSS for desktop and mobile devices. However, I noticed that when resizing the browser to under 855 pixels, some of the mobile CSS is ...