I've written a simple jQuery (1.4.2) UI (1.8) widget that embeds a jQuery UI datepicker. I'd like to detect when a user clicks outside my widget, in which case it should automatically hide itself. My code looks roughly 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 comes when clicking on a date or month prev/next button in the datepicker. For some reason, even though Firebug shows those elements as being descendants of my container, the has() check fails for them.
What is happening, and how might I fix this?