1

I have a case where on clicking a link, I am showing a tooptip. I want to hide the tool tip when the user clicks anywhere else on the screen(even some other link). Below is the code I have...

$('a.tooltip').click(function(event){
    $('a.tooltip span').hide();
    $(this).children("span").show();
});

The above function shows/hide the tooltips when clicked on the a tags.

$(document).click(function(event){
    if(event.target != 'a.pull-right plus tooltip'){
        $('a.tooltip span').hide();
    }
});

Since event.target gives me the entire HTML target, I am not able to distinguish between clicks. Is there some way to do this?

4

1 回答 1

2

编辑:尝试这种方式也许:

$(document).not('a.tooltip').click(function(event){
    $('a.tooltip span').hide();
});

$('a.tooltip').click(function(event){
    event.stopPropagation();
    $('a.tooltip span').hide();
    $(this).children("span").show();
});
于 2013-10-04T00:28:01.710 回答