Reputation: 4828
I have a div
with id area
on my page.
I want to show a close icon at right corner(it is inside the div) when user's mouse enter on this DIV
. Everything is working fine but the issue is when user hover on close icon #closeicon
area , it will hide the icon.
So please suggest how can i keep on showing the close icon when user hover on it.
Here is my code:
$("#area").on('mouseenter',function(e){
e.stopPropagation();
showCloseIcon();
}).on('mouseleave',function(e){
e.stopPropagation();
var except=$("#closeicon");
if(!except.is(e.target) && except.has(e.target).length===0){
hideCloseIcon();
}
});
EDIT
closeicon is not the child of the area DIV. I am positioning it over area div using css(absolute position) due to some reason.
Upvotes: 0
Views: 190
Reputation: 33880
You can use this code :
$('#area, #closeicon').hover(function(){
$('#closeicon').show();
}, function(){
$('#closeicon').hide()
})
Just bind your event on both id's.
Also, I used .hover
since it shorter and do the same thing as .mouseenter()
and .mouseleave()
. in the same call.
Fiddle : http://jsfiddle.net/S9LQY/
Upvotes: 1
Reputation: 7609
I'm not sure if this is something you're looking for, but you can just use CSS for this:
#closeicon {
display: none;
}
#area:hover > #closeicon {
display: block;
}
Upvotes: 0