I am currently working on creating a function that displays a button when the mouse hovers over an element and hides it when the mouse is moved away. The example below illustrates my issue:
------------------------------------------------------------
---------
| button2 | DIV#1 Button1
| |
| DIV#2 |
| |
----------------------------------------------------------
| |
-----------
**The CSS**
#div1{
height: 200px;
width:500px;
position: relative;
}
#div2{
height: 150px;
width: 150px;
left: 19px;
top: 76px;
position: absolute;
}
**Javascript**
$("#button1").hide();
$("#button2").hide();
$('#div1').mouseover(function() {
$("#button1").show();
});
$('#div1').mouseout(function() {
$("#button1").hide();
});
$('#div2').mouseover(function() {
$("#button2").show();
});
$('#div2').mouseout(function() {
$("#button2").hide();
});
HTML There are many elements in my document, but for clarity:
<div id='div1'> <div id='div2'>example button2 </div> example button1 </div>
The issue at hand:
When hovering over DIV#2, Button1 also shows up. It seems like these two divs are somehow connected. Is there a way to ensure that Button1 only displays when hovering over DIV#1?
I attempted to use z-index, but it did not solve the problem.