Hide a DIV when it loses focus/blur

后端 未结 11 583
长情又很酷
长情又很酷 2021-02-05 08:34

I have a JavaScript that displays a DIV (sets its display css property from \'none\' to \'normal\'. Is there a way to give it focus as well so that when I click somewhere else o

11条回答
  •  生来不讨喜
    2021-02-05 09:11

    For the hide the div when clicking any where on page except the selecteddiv

    $(document).not("#selecteddiv").click(function() {
            $('#selecteddiv').hide();
        });
    

    if you want to hide the div with lost focus or blur with animation then also

    $("#selecteddiv").focusout(function() {
            $('#selecteddiv').hide();
        });
    

    with animation

    $("#selecteddiv").focusout(function() {
        $('#selecteddiv').animate({
            display:"none"
        });
    });
    

    May this will help you

提交回复
热议问题