jquery: div hide/show on focus issue

后端 未结 2 1744
眼角桃花
眼角桃花 2021-01-26 12:55

Thanks to inti\'s code I was able to figure out the answer!

jQuery:

$(document).ready(function(){
    $(\"body\").click(function(e) {
          


        
2条回答
  •  旧巷少年郎
    2021-01-26 13:31

    The event you are looking for is .blur() not .focusout().

    Edit: click out of #mydiv to hide it:

    $("body").click(function(e) {
        if ($(e.target).closest("#mydiv").size() == 0) {
            $("#mydiv").hide();
        }
    });
    

    This hides #mydiv if what you clicked doesn't have it as one of it's parents.

提交回复
热议问题