Skip to content Skip to sidebar Skip to footer

JQuery Click Handler For Everything But A Certain Object

How do I check for a click on everything but a certain object? I use (not), but I'm not sure how to call the class / id of the entire page. $('.page').not('#divInfoBox').click(func

Solution 1:

Try this:

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

});

Read the doc page for the not selector:

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


Solution 2:

You can add a click event to the "html" element. That way you get events even if you're "off" the page:

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

Demo can be seen here: http://jsbin.com/eguti


Solution 3:

Your missing the ); at the end, should be like this:

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

As for your question, the 'page' div is not extending to the bottom of the page so you need to register the function to work on the body tag.

Also it looks like you are making a popup appear when certain things are clicked and disappear when clicked off to the side. I would recommend looking for a plugin that will handle this for you. I know there are several. Personally I like jqModal.


Post a Comment for "JQuery Click Handler For Everything But A Certain Object"