jQuery function to hide elements

0

I have a window that opens when I click on an element, blz. But how can I do to, by clicking OUTSIDE this window, it closes?

    
asked by anonymous 21.05.2014 / 19:53

2 answers

4

Treat this as an ancestor of the element you want to hide:

$(document).on('click', function(e){
    // verifique se o clique veio de dentro da sua janela.
    // para isso use e.target (a origem do clique).
    // se não tiver vindo da sua janela, feche a janela.
    // exemplo:
    if(!$('#janela').contains(e.target)) {
        $('#janela').close()
    }
});
    
21.05.2014 / 19:56
0

I think there should be some kind of mask behind that content, right?

Do something like this:

$("#mascara").click( function(e){
    e.preventDefault();
    $(".sua-tela").fadeOut(function(){
         $(this).hide();
         $("#mascara").hide();
    });
});
    
21.05.2014 / 20:12