How to extract a div from its parent using jQuery

I need to stack two div boxes on top of each other, and my goal is to hide the upper one when it's being hovered over. HTML:

<div id="left_middle">
<div id="rfinder_UP"></div>
<div id="rfinder_DWN"></div>
</div>

CSS:

#left_middle {
position:relative;
float: left;
width: 235px;
min-height: 220px;
background:green;
margin-right: 10px;
 -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    -khtml-border-radius: 5px;
    border-radius: 5px;

}

#rfinder_UP, 
#rfinder_DWN {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
     -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    -khtml-border-radius: 5px;
    border-radius: 5px;
}

#rfinder_DWN{
background: url(images/rfinderapp_DWN.png) no-repeat;

}

#rfinder_UP {

    background: url(images/rfinderapp_UP.png) no-repeat;
  z-index: 10;
}

JS

$(document).ready(function(){
$("#rfinder_UP").mouseover(function(){
  $("#rfinder_UP").hide();
  });
$("#rfinder_DWN").mouseout(function(){
  $("#rfinder_UP").show();
  });
});

Now I would like to achieve this by not only hiding the upper div with .hide but somehow pull it out of the left_middle div from the bottom. Is there an easy way to do this? I tried a lot of different other jQuery effects like animate, slideDown etc. but couldn't find a working solution.

Thanks in advance!

A jsFiddle demonstration can be found here: http://jsfiddle.net/qEcp8/ The red box simply disappears on hover revealing the black one. My desired effect is for the red box to slide down, out of the left_middle box.

Answer №1

$( "#rfinder_UP" ).hover(function() {

  $('#rfinder_DWN').animate({height:"100%"});
}, function() {
  $('#rfinder_DWN').animate({height:"0"});

}
);

Check out the demonstration here: http://jsfiddle.net/EyVd6/1/

I have made changes to your HTML and CSS based on the code provided...

Answer №2

Give this a shot:

#rfinder_UP:hover {
    visibility:hidden;
}

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

Difficulty encountered when consolidating intricate data attributes into a single array

I have a task to tackle in the code snippet below. My goal is to collect all the data in the age attributes and store them in a single array, formatting it as shown here: output = [48, 14, 139, 49, 15, 135, 51, 15, 140, 49, 15, 135, 51, 15, 140, 52, 16, ...

IE11 is unable to display the background image

I am attempting to create a process roadmap by using background images on list items. The background-image on the list item is not showing up in IE11 (also in all versions of IE10, 9, etc). CSS CODE body{padding: 50px 0;} .status-line { width: 80%; ...

What strategies can be employed to preserve certain fields while dynamically populating others using JSON in a form?

Currently, I am utilizing jquery Populate to dynamically fill a field with the information from the previous Firstname and Surname fields within the same form. However, an issue arises when using the Populate javascript function: $(formname).populate(newfi ...

Is it better to store JSON data locally using cookies or HTML5 local storage?

Currently, I am working on developing a mobile website using jquery mobile. My main concern right now is how to efficiently carry JSON data across multiple pages. I am debating whether it would be better to store this JSON data in a cookie or use HTML5 loc ...

Ensure that the text box inside the div adjusts its size in accordance with the dimensions of the window, as the div is already designed

As a novice in HTML and jQuery, I am currently working on creating a portfolio site for a school project. One of the challenges I have encountered is designing a graphic that includes a text box within a resizable div element. My goal is to prevent excessi ...

When I switch to mobile view, my navigation menu vanishes

Currently in the process of creating a website using WordPress, specifically with a divi theme and utilizing a windows operating system. It seems that everything appears correctly on desktop, however when resizing the window or viewing the site on a mobile ...

Using CSS to ensure that the cards have consistent heights when using both React and Bootstrap

I am currently working with Bootstrap 4 in React. I have encountered an issue where the card for Item 1 is shorter than that of Item 2, and I would like both cards to have the same height. Additionally, I anticipate adding more cards at the bottom in the ...

Advantages of Using JSON for POSTing Data to a Server with jQuery

While browsing the internet, I've come across various examples of using jQuery to send AJAX POST requests with JSON encoded data to a server. I'm curious about why it's necessary to encode the data in JSON first. Wouldn't it be more eff ...

Breaking Free from Bootstrap Grids

I have a row with two Bootstrap columns - one wide and tall, the other short and narrow https://i.sstatic.net/u7WAf.png However, for mobile devices (targeted below lg), I want to change the column order to split into three sections Photo Consent Organis ...

How can jQuery be forced to accept an XHTML string as XML?

For my OpenID implementation in Javascript, I'm using AJAX to fetch a remote page source and searching for the <link rel="openid.server" href="http://www.example.com" /> tag within the head section. I have opted for the jQuery library for the AJ ...

Is there a way to duplicate items similar to MS Word by using a combination of ctrl + mouse click +

In my fabricjs application, I currently clone an object by clicking ctrl + left mouse click on it, which works fine. However, I would like to be able to clone the object in a similar way to MS WORD, by using ctrl + click + drag. Has anyone achieved this f ...

Gridview displaying varying border styles in CSS

I'm really struggling with this issue. I have a GridView and I want to ensure that the borders are consistent across all browsers. Right now, I'm experiencing different outcomes in IE, FF, and Chrome. Despite my best efforts with CSS (I'm re ...

Reviewing user input for any inappropriate characters using jQuery's functionality

When a username is inputted into the input box, I want to make sure that only valid characters are accepted. The following code shows what I have so far; but what should I replace "SOMETHING" with in the regular expression? var numbers = new RegExp( ...

Associating checkbox options with an array that is void of elements

I have a series of arrays linked to checkboxes and I am trying to create a unique array based on the selected checkbox values. Here is an example of the HTML structure: <input type="checkbox" value="value1">Value 1 <input type="checkbox" value=" ...

Customize Joomla content in a component by using CSS within a template that I personally designed

Is there a way to customize the text content of a component in Joomla by editing the body text? The CSS properties for #content are adjusting padding, margin, border, width, height, and background but not affecting font attributes... Inside index.php < ...

Learn how to maintain floating labels in a floating state even after text input using only CSS

Figured out how to make labels float above form input fields when focused, but struggling with keeping them floating when text is entered and field is unfocused. Been searching for CSS examples online, but none seem to clarify how to achieve the desired e ...

Generating multiple div elements within an AJAX iteration

Currently, I am retrieving data from the server side using AJAX. My goal is to populate data from a list of objects into divs but I am facing an issue where I cannot create the div while inside the foreach loop. $(document).ready(function () { var ...

What is causing the extra space on the right side of the box?

I've been struggling to align text next to an image inside a box. Desired outcome CSS: #roundedBox { border-radius: 25px; background: #363636; width: auto; height: auto; margin: 10%; display: flex; position: relative; ...

Utilize AjAx and the post method to transmit data to a servlet

function checkInputValue (value){ var input = value; $.ajax({ url:"ggs.erm.servlet.setup5.AjaxS", data:{ userInput :input}, success:function(){ alert("Success! Code executed successfully."); } }); } ...

Delay fading in during the loading process

Recently, I came across a neat animation effect that I would love to incorporate into an upcoming project. The effect involves animating the opacity on load, also known as a fade in. I am curious if it is possible to link multiple elements together (for ...