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

Tips on utilizing jquery slideDown alongside appendTo

I am currently utilizing an ajax request to retrieve records from the database and then appending the data in HTML. However, I want the HTML to slide down once the data has been appended, but I'm unsure of how to achieve this. Below is the ajax metho ...

When looking at the table, it will only read integer values for EmpID. However, if it is a string value

This method on a website uses AJAX and jQuery. When the EmpID is in the format of 123, 12, or 123456, it opens a popup box and displays the desired output. However, when the EmpID is in the format of A001 or ABC, it displays an error message saying "Error ...

The media query was running smoothly until it unexpectedly stopped functioning

I've encountered an issue where something that used to work perfectly fine suddenly stopped working :( @media only screen and (max-width: 768px) { form, button, input { width: 80vw !important; } } <meta name="viewport" content="width=de ...

Need to delete the product page link on WooCommerce?

I am currently working on fixing the one-page checkout process and I need to remove a single product link from a product picture. The goal is to have only the checkout link displayed on this page, specifically within a quickview view. After trying out var ...

Retrieve information from an ajax call within an Angular application

I need assistance with 2 requests I have. $.ajax({ type: "POST", url: "http://sandbox.gasvisor.com:9988/uaa/oauth/token", data: "grant_type=client_credentials", headers: { 'Content-Type': 'application/x-www-form-urlencoded&a ...

Trouble with sending data from $.ajax to my demo.php file

I'm having an issue with sending data to the demo.php file using my code. This is the code I am working with: <script src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script> function update(str) { var str2=s ...

Comparison: JavaScript Cookies vs PHP Cookies

I have been trying to implement the following code: JS: Cookies.set(post_id + '_' + user_ip, post_id + "_" + user_ip, { expires: 1 }); PHP: $cookie_str = $post_id.'_'.get_client_ip(); if (isset($_COOKIE[$cookie_str_]) ){ print_r ...

Most Effective Method for Switching CSS Style Height from "0" to "auto"

After coming across a question with no answer that suited my needs, I decided to share the solution I created. In my case, I had a hidden generated list on a page which was initially set with a CSS height of "0" and then expanded upon clicking by transit ...

Generate a new cookie only when it is not currently present

My objective is to: Determine if a cookie named "query" exists If it does, take no action If not, create a cookie called "query" with a value of 1 Please note: I am working with jQuery version 1.4.2 and utilizing the jQuery cookie plugin. Any recommend ...

Transform all characters to lowercase, then capitalize them using only CSS

I came across a discussion on this topic at: First lowercase the text then capitalize it. Is it possible with CSS? However, the solution provided was not purely based on CSS. I have a div that contains the following text: <div> RaWr rAwR </div&g ...

Ensure that the mask implemented in the form input only shows two decimal places, while simultaneously retaining the original value

Is there a way to format a number in a form input so that it displays only two decimals while still retaining the original value? This is necessary to avoid incorrect values down the line and meets the customer's requirement of showing no more than tw ...

Ways to incorporate a scroll feature and display an iframe using JQuery

Is there a way to animate the appearance of hidden iframes one by one as the user scrolls down the website using jQuery? I have come across some solutions, but they all seem to make them appear all at once. I'm looking for a way to make the iframes s ...

Problem uploading files with ajax in Laravel version 6

I am encountering an issue while attempting to save a PDF file along with other input values using Ajax in Laravel 6 without utilizing the form HTML element. The error message "Call to a member function getClientOriginalExtension() on null" keeps popping u ...

Google Sheets displaying blank values after submission via an AJAX call

I have been working on transferring data from my web app to a Google spreadsheet and I am encountering some issues. I followed the script provided by Martin Hawksey, which can be found here: https://gist.github.com/mhawksey/1276293 Despite setting everyth ...

Asp.Net feature for adding comments

I currently have a page where users can leave comments, which are then stored in a database table. When the user submits a comment, it is displayed on a datagrid after a postback. However, I would like to enhance the presentation of these comments and ma ...

Dynamic population of dropdown not working as expected

Below is the code I am using to populate a Dropdown: $(document).ready(function(){ $('#inDistrict').sSelect(); $("#inDistrict").change(function(){ $.getJSON("filldistricts.php",{id: $(this).val(), ajax: 'true'}, function(j) ...

Reposition buttons using JavaScript

I attempted to modify the button that appears at the top of an HTML page. <div class='play'> <input id="play" type="button" value="Play" onclick="mode('play');startSlideshow();" /> </div> <div class='pause ...

Navigating the absence of Prismic's ability to use the <blockquote> element in their rich text editor

My experience with Prismic as a headless CMS has been mostly positive, but I recently encountered an issue that surprised me - the lack of support for a simple blockquote. It's baffling to me that such a basic HTML element is not natively supported by ...

Excessive width of the lower border

I have a dropdown menu on my website and I wanted to add a border-bottom to the menu. However, the border appears too wide. I went through every step of this solution as it seemed like the same problem, but nothing seems to be working. It would be great i ...

"Enhancing the user experience: Triggering a window resize event in jQuery before page load on Magento

I am trying to trigger this function before the page finishes loading, but currently it only triggers after the page has loaded. Can anyone assist with this issue? $(window).on('load resize', function(){ var win = $(this); //this = window ...