Hide div when clicking on it

0

How can I do to click on the div and stop displaying it? I'm using onClick but it's not running.

My div:

<div class='alert alert-danger aviso' role='alert' style='width: 20%;'>Falha ao carregar os dados!</div>

onClick:

$('.aviso').on("click", function () {
                    $('.aviso').hide();
                }
    
asked by anonymous 14.08.2018 / 15:35

2 answers

1

If you have placed your complete code, you are missing a click assignment, a ); is missing at the end. I think this is because I put your code in a fiddle and it worked, and here in the snippet too:

$('.aviso').on("click", function () {
  $('.aviso').hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class='alert alert-danger aviso' role='alert' style='width: 20%;'>Falha ao carregar os dados!</div>

Incidentally, to ensure that I will close only the div that was clicked, I suggest replacing the line $('.aviso').hide(); with $(this).hide();

    
14.08.2018 / 15:46
0

Hide example with jquery

Other types of animations can still be added. By default it is swing.

    
14.08.2018 / 16:01