I have such a problem. On mouse enter, I want red circle to be changed with blue circle. But by this code, I have two circles on screen and red of them disappears on mouse enter. How to solve this problem?
$(document).ready(function(){
$('.red').mouseenter(function(){
$('.blue').show();
}, function(){
$('.red').hide();
});
});
.red{
margin-left: auto;
margin-right: auto;
width:200px;
height: 200px;
background-color: red;
border-radius: 150px;
display: flex;
align-items: center;
justify-content: center;
}
.blue{
margin-left: auto;
margin-right: auto;
width:200px;
height: 200px;
background-color: blue;
border-radius: 150px;
display: flex;
align-items: center;
justify-content: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="circles">
<div class="red">red circle</div>
<div class="blue">blue circle</div>
</div>
4
Answers
Try this way, it should help:
I’d use 1 circle on which you toggle the
background-color
onmouseenter
andmouseleave
Since you Might Not Need Jquery, a pure JavaScript version of the above:
I don’t know what you are trying to achive, But as I undestood I’ve added the code. I hope this will help you.
By default hide the blue circle and bind mouse event on parent