The input field inside the div disappears when the mouse leaves

I need to create a div that remains visible as long as the mouse hovers over it, but disappears when the mouse moves off. Additionally, I want a sign-up form to appear on hover and disappear once the sign-in process is complete. Check out the jsFiddle Demo for reference.

HTML

<div class="members">
    <a href="#" id="signUp" class="box">Members</a>
    <div id="sign-up-form" class="sign-up-form">
        <input type="text" name="firstName">
    </div>
</div>

JS

var signUp = document.getElementById('signUp');
var signUpForm = document.getElementById('sign-up-form');

signUp.onmouseover = function(){    
    signUpForm.style.display = 'block';
}
signUpForm.onmouseout = function(){
    signUpForm.style.display = 'none';
}

CSS

#signUp{
    position: relative;
    background-color: red;
    color: white;
    padding: 6px;
}

#sign-up-form{
    display: none;
    position:absolute;
    top: 32px;
    left: 8px;
    background-color: rgba(0,83,159,0.6);
    padding: 15px;
}

Answer №1

If I were to implement this, I would exclusively utilize CSS:

#register-form {
    display: none;
}

.visitors:hover #register-form {
    display: block;
}

Answer №2

This particular demonstration showcases the implementation of mouseover and mouseout event listeners along with a function designed to monitor all child elements before altering the appearance of the signUpForm element.

function outVis(event) {
        var e = event.toElement || event.relatedTarget;
        if (e.parentNode == this || e == this) {
           return;
        }
    signUpForm.style.display = 'none';
}

http://jsfiddle.net/9xhb532v/1/

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

IntelliJ Community offers comprehensive support for React.js development

Looking for a free React.js plugin with features like syntax highlighting and autocomplete that can be used in IntelliJ Community edition. Considering migrating from Ultimate license to Community edition. Found some answers on stackoverflow but none were ...

A specific string exemption for HTML even numbers

Within this HTML code, I have specified that the even-numbered rows should have a different format. However, if the string "QACheck:" appears in a row, I want to use the odd-numbered row format. Even if it occurs in an even-numbered row. Can someone assis ...

Is there a way to conceal JavaScript code?

I am trying to keep my AJAX code hidden from users who view the source of my PHP page. How can I achieve this? Below is the AJAX code that I currently have: <script type="text/javascript"> function Ajax(){ var xmlHttp; try{ xmlHttp=n ...

Tips for utilizing innerHeight for a div during both window loading and resizing tasks?

I'm currently working on calculating the top/bottom padding of a div (.content) based on its height, and updating it upon loading and resizing the window. The goal is to have it centered nicely next to another div (.character) positioned beside it. I ...

`Is there a clash between UpdatePanel and RegisterStartupScript?`

I am facing an issue with the client-side validation in my user control. Everything works fine when the user control is placed on a page, but if there is a postback event (like selecting an option from a dropdown that displays more fields), the validation ...

Ways to invoke a function in Angular2 when the Boolean condition is met

Within my component class, I have implemented a popup function along with a Boolean flag that returns true or false based on specified conditions. In the template class, I want the popup function to be triggered when the flag becomes true, displaying a pop ...

Adjust the position of the background when hovering with the mouse to create a right

Currently, I am implementing a background perspective change with the use of mousemove. However, an issue arises with the right margin of the image after moving it. Everything looks fine initially. Any suggestions on how to prevent this problem? https:/ ...

Creating a table using jQuery and JSON

Could someone assist me in figuring out how to add a new table row every time the loop starts? Here is my jQuery code: var row = $("<tr></tr>"); $.each(data.response.docs, function (i, item) { row.append('<td>' + ...

"Learn the process of transferring data from one controller to another in your application

After adding categoryCtrl and ProductCtrl, the code line: console.log(category); is functioning correctly. I am looking for a way to bind this data to the product controller using a for loop or any other method. .controller('CategoryCtrl', funct ...

Ensuring the accuracy of a single field within a form containing multiple fields is made possible through the utilization of

I am facing an issue with my emailValidation method. Even though I want it to run when this.$refs.editUserForm.validate('email') returns true, it always seems to return false, especially when a valid email like <a href="/cdn-cgi/l/email-protec ...

Tips for implementing FontAwesome in Nuxt3

I'm facing some issues trying to implement FontAwesome in my NuxtJS project, and for some unknown reasons, it's not working as expected. Let's take a look at my package.json: { "private": true, "scripts": { " ...

Transferring an image to an internet-based storage system/database through XMLHttpRequest (XHR)

After reading several posts on similar topics, I have yet to find the specific information I need. Currently, I am working on a web application (utilizing HTML5 and Javascript) that includes a photo-taking feature. I am looking to then save these photos t ...

React/Redux does not retain previous items with Infinite Scroll

I am currently facing an issue where the new set of items loaded from the reddit API using Infinite scrolling overrides the previous items when the user scrolls to the bottom of the page. Although the new items load successfully, they replace the existing ...

Eliminating the use of am/pm and implementing a 24-hour format on the x-axis of a time series

Currently, I am attempting to create a time series plot with second precision in the format of HH:mm:ss (24 hours per day), as indicated in the documentation provided by moment js. However, I have encountered an issue where the format I specify is not bei ...

Transferring data from local storage to a PHP server using AJAX

My attempt to transfer data from local storage to PHP using AJAX resulted in an error mentioning 'undefined index data'. chart.php <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="t ...

How to integrate a custom service worker in create-react-app without the need for ejecting

I have an app that I want to switch over to React. I've created a new version of the app using create-react-app (with react-scripts 1.0.13) to mimic the functionality of the existing app. The challenge I'm facing is integrating the existing serv ...

Implementing standard Header and Footer elements in Vue.js single-page applications

I'm currently working on a VueJS project for a spa. I've already created common components for the Header and Footer, and now I want to include them in the main App.vue file. Here is the structure of my code: https://i.sstatic.net/qdLam.png Le ...

I'm searching for a universal guidebook on creating web page layouts

After 5 years of creating webpages, I have realized that my sites tend to have a nostalgic 1995 internet vibe. Despite being a C# programmer with knowledge in HTML, JavaScript, and CSS, my design skills could use some improvement. Is there a quick referenc ...

Breaking down nested arrays in typescript

After receiving a response from the service, the data included the following: "rows": [ [ "stravi/aa", "202001", "59", "51", "2558.98", "0.5358894453719162", "1.9204668112983725", "140", "2.346630 ...

If an element contains a specific class, then set its display property to none

I am attempting to utilize the hasClass method in JavaScript to determine whether a div should be hidden (display: none) or kept visible as usual. Below is the snippet of code I currently have: if (!$('cool').hasClass('hot')) { ...