Try: this.fn = function(event){ var element = event.target, stop = false;
while (element != document.body && element.nodeType == 1){ if (element == this.calendar) stop = true; this.calendars.each(function(calendar){ if (calendar.button == element || calendar.els.contains(element)) stop = true; }); if (stop){ event.stop(); return false; } element = element.getParent(); } this.toggle(cal); }.bind(this);