Use bootstrap alert 3

1

I'm trying to use bootstrap alert in a project, but I'm having a hard time doing it, what I have at the moment is this:

if (sNome == "" || sTel == "" || sCEP == "" ){
    $("p.erro").html("Todos os campos devem ser preenchidos");
    return false;
} else if ( !(emailFilter.test(sEmail)) || sEmail.match(illegalChars) ){
    $("p.erro").html("Por favor, informe um email válido.");
    return false;           
}

And I'm displaying the message this way:

<p class="erro" align="center"></p>

But I would like to be able to display in this format:

<div class="alert alert-danger">
<strong>Atenção: </strong> Todos os campos precisam ser preenchidos.</div>

When trying to make this change, the div of the alert is always visible, I tried to change it this way:

$(".alert").html("Todos os campos devem ser preenchidos");

But as I said it was not correct.

    
asked by anonymous 07.11.2016 / 12:18

1 answer

3

You can add the class hidden to your div, it would look like this:

<div class="alert alert-danger hidden"></div>

And in the javascript call you just need to add the show method of jQuery

$(".alert").html("<strong>Atenção: </strong> Todos os campos devem ser preenchidos").show();
    
07.11.2016 / 12:26