JQuery handler for everything except a specific object

How to check a click on everything except a certain object?
I use (not), but I'm not sure how to call the class / id of the whole page.

$(".page").not("#divInfoBox").click(function (event) { } 

What is the correct way to specify page in the HTML code, since I have something like:

 <html> <body> <div class="page"> </div> </body> </html> 

I see the following: clicking on the top half of the page works; but at the bottom of the page, where there is nothing but the background color, the click is not registered, because it is "outside the page" - how can this be expanded so that the click works everywhere?

Thanks Michael

+3
jquery html
Jul 10 '09 at 14:22
source share
3 answers

You can add a click event to the "html" element. This way you get events even if you are "turned off" on the page:

 $("html").click( function() { ... } ); 

The demo can be seen here: http://jsbin.com/eguti

+1
Jul 10 '09 at 14:28
source share
— -

Try the following:

 $("body:not('#divInfoBox')").click(function (event) { }); 

Read the document page for the not selector:

http://docs.jquery.com/Selectors/not

+10
Jul 10 '09 at 14:25
source share

Absent); at the end, should be as follows:

 $(".page").not("#divInfoBox").click(function (event) { // do something }); 

As for your question, the div 'page' does not extend to the bottom of the page, so you need to register a function to work with the body tag.

It also looks like you are creating a popup when some things click and disappear when you click on a side. I would recommend looking for a plugin that will handle this for you. I know that there are several. Personally, I like jqModal .

-one
Jul 10 '09 at 14:25
source share



All Articles