hd.
hd.

Reputation: 18306

Hide a block on losing focus

I have a sub-menu. I want to hide it when user clicks anywhere outside it. I try focusout() and blur() jQuery methods, but they don't work.

Upvotes: 0

Views: 169

Answers (2)

xiaowl
xiaowl

Reputation: 5207

// listen click event on document   
$(document).click(function(e){
    // if the event is not triggered by your submenu, hide it.
    if(e.target.id != id_of_sub_menu){
        $("#id_of_sub_menu").hide();
    }
});

Upvotes: 1

dhiraj karn
dhiraj karn

Reputation: 1

// here is div whose id is 'block'

$(document).ready(function() {
    $('#block').mouseout(function() {
       $(this).hide();
    })
});

Hope it helps!!

Upvotes: 0

Related Questions