I display an abolute
div
with a jQuery $.animate({height: 'toggle', opacity: 'toggle'})
on a jQuery $.hover()
.
I have a jQuery UI datepicker attached to a div within the aforementioned absolute
div
with changeMonth: true
and changeYear: true
.
When a month or year are changed or a date is selected the animation fires.
How can I prevent the month/year change & date selection from triggering the $.hover()
?
html
<div id="hoverAnchor">hover me</div>
<div id="hoverMe" style="display:none">
arbitrary text
<div id="dateSelector"></div>
</div>
js
$(document).ready(function () {
$("#dateSelector").datepicker({
changeMonth: true,
changeYear: true
});
$("#hoverAnchor").add($("#hoverMe")).hover(function(){
$("#hoverMe").stop(true,false).animate({
height: 'toggle',
opacity: 'toggle'
}, 200);
});
});
You need to do a couple things in order for this to work properly.
First, you need to wrap the HTML in a
div
to act as the container:HTML:
Next, rather than using
.hover()
(which can sometimes be unreliable), I recommend using.mouseenter()
along with.mouseleave()
. Also use avar
to hold boolean of whether datepicker open/closed. The reason for this boolean is due to theinput
. On click, a second.mouseenter()
event will be called, so without it,#hoverme
would toggle a second time.DEMO: http://jsfiddle.net/dirtyd77/e3zP2/18/
Hope this helps!