Display a div for a given time Jquery

0

I would like to know, if you have how I present the contents of a div at a given time. Well, in this case I'm inserting an html into the div and after a while I'd like it to disappear, have you any way to do that?

    <div id="alerta">

    </div>

@if (cadastradoComSucesso)
{
    <script>
        var functionSuccess = function () {
            $('#alerta').html('<div class="alert alert-success" role="alert"> Registro cadastrado com sucesso.</div>')
        };        
        setTimeout(functionSuccess, 8000);     
    </script>
}
else
{
    <script>
        var functionWarrning = function () {
            $('#alerta').html('<div class="alert alert-warning" role="alert"> Erro ao salvar registro.</div>')
        };
        setTimeout(functionWarrning, 8000);        
    </script>

}
    
asked by anonymous 23.10.2017 / 19:25

2 answers

1

You can use setTimeout and then hide in the div.

setTimeout(function(){
   //Esconde a div
   $('#alerta').hide();
}, seu_tempo_em_millisegundos);
    
23.10.2017 / 19:35
0

I got this way:

<script>
    var functionWarrning = function () {
        $('#alerta').html('<div class="alert alert-warning" role="alert"> Erro ao salvar registro.</div>')
        $('#alerta').show();
    };

    functionWarrning();

    setTimeout(function () {
        $('#alerta').hide();
    }, 8000);         
</script>   
    
23.10.2017 / 19:34