+1  A: 

You can capture the target element, e.g.:

$('*').click(function(e) {
    alert(e.target);
    alert(e.target.tagName);
    if(e.target.tagName == 'html') {
        // show background menu
    }
});
karim79
there's going to be a LOT of overhead in a function like that. It would be better to use `.live('click', function() { ... })` - or better yet, just apply it to `$('html')`
nickf
The selector was not really the point of the answer, the point was how to get the clicked element. Anyway, thanks for your comment. Oh, and how would `live` incur less overhead?
karim79
A: 

You have to work with the Javascript Event Propagation model. What happens is that your click event is automatically passed down the layers of objects on a page that have been registered as event listeners, unless you explicitly tell it to stop, try something like this:

function setupClickHandlers()
{
    document.getElementsByTagName('body')[0].onclick = doBodyMenu;
    document.getElementById('tableID').onclick = doTableMenu;
}

function doBodyMenu()
{
    //do whatever it does
}

function doTableMenu(e)
{
    //do whatever it does

    //stop the event propagating to the body element
    var evt = e ? e : window.event;

    if (evt.stopPropagation) {evt.stopPropagation();}
    else {evt.cancelBubble=true;}
    return false;
}

This should deal with the way each browser handles events.

MalphasWats
This worked for me. Thank you for the quick response. Just to make sure, does it always call in the order of innermost element to outermost element? i.e. table cell's onclick -> table row's onclick -> table's onclick -> body's onclick?
Travis
it should do yes.
MalphasWats