I wrote a simple jQuery (1.4.2) UI (1.8) widget that embeds the jQuery UI datepicker. I would like to detect when a user clicks outside of my widget, in which case he should automatically hide. My code looks something like this:
var self = this;
$(document).bind("click.mywidget": function(event) {
var target = event.target;
if (!self.container.has(target).length && target != self.container.get(0)) {
self.hide();
}
});
The problem occurs when pressing the date / month button prev / next in the datepicker. For some reason, although Firebug shows these elements as descendants of my container, the has () check fails with an error for them.
What is happening and how can I fix it?
source
share