Add event to all elements except the given with jQuery

Posted by Metropolis on Stack Overflow See other posts from Stack Overflow or by Metropolis
Published on 2010-03-19T19:45:21Z Indexed on 2010/03/19 19:51 UTC
Read the original article Hit count: 227

Filed under:
|
|
|

Hey everyone

I created a date picker that uses ajax to populate an element with an id of calendarContainer. When the user clicks on a button to bring the calendar up, I want the user to be able to click anywhere else on the screen besides the calendar and have it hide. The calendarContainer is at the root of the dom and I have tried everything I can think of to get this working.

I have gotten the calendar to go away when it is not clicked on. However, when I click on the calendar it is also going away. I only want the calendar to go away when it is not clicked on.

Here are all of the things I have tried.

$(":not(#calendarContainer > table)").live('click', function() { $.Calendar.hide(); });
$(":not(#calendarContainer").live('click', function() { $.Calendar.hide(); });
$(":not(#calendarContainer)").click(function() { $.Calendar.hide(); });
$("body:not(#calendarContainer)").click(function() { $.Calendar.hide(); });
$(":not(#calendarContainer, #calendarData)").live('click', function() { $.Calendar.hide(); });

Thanks for any help, Metropolis

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about selectors