Function jQuery to hide elements

Asked

Viewed 149 times

0

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

  • I got it guys. I just needed to know how I could sweep all my DOM behind a class and display it/hide it.

  • I suggest posting your answer below, as an answer, so you can help other people with the same problem. If you want, you can even mark your own answer as accepted. For details see http://meta.pt.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-reply

2 answers

4

Treat it to 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()
    }
});

0

I believe you must have some sort of mask behind that content of yours, correct?

Do something like that:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.