jQuery Close DIV By Clicking Anywhere On Page

后端 未结 5 769
夕颜
夕颜 2021-01-13 11:07

I would like to open email-signup when I click on email-signup-link. Then I would like to close it by clicking anywhere on the page except for the

5条回答
  •  隐瞒了意图╮
    2021-01-13 11:39

    Two things. You don't actually have e defined, so you can't use it. And you need stopPropagation in your other click handler as well:

    $('#email-signup').click(function(e){
        e.stopPropagation();
    });
    $("#email-signup-link").click(function(e) {
        e.preventDefault();
        e.stopPropagation();
        $('#email-signup').show();
    });
    $(document).click(function() {
        $('#email-signup').hide();
    });​
    

    http://jsfiddle.net/Nczpb/

提交回复
热议问题