Use bootstrap Alert 3

Asked

Viewed 779 times

1

I’m trying to use bootstrap Alert in a project, but I’m having trouble 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 wish I could show it in this format:

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

In attempting to make such a change to div of alert is always visible, I tried to make the change in that way:

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

But like you said, it wasn’t right.

1 answer

3


You can add the class hidden your div, would be like this:

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

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

$(".alert").html("<strong>Atenção: </strong> Todos os campos devem ser preenchidos").show();
  • Hello @Felipe Nascimento, thanks for the suggestion, I changed the code as indicated, but now the div does not appear with the message.

  • 1

    Strange, then try to replace the show function by . removeClass("Hidden");

  • Great help @Felipe Nascimento, now worked out, again thanks.

Browser other questions tagged

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