Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

341
Vistas
Hide and show div using Jquery not working

I have created a form and JQuery Ajax handler to handle the login.
Under my form I have created a bootstrap div popup that tells "Username or password incoorrect". I want to hide it using JQuery $().hide() and my Handler script will show the div popup if the username and password are not in the database.

This is the div popup

<div id="error" class=" col-sm-3  mx-auto  mt-4 alert alert-danger alert-dismissible fade show" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
  Password or username incorrect.
</div>

This is my JS Script

$(`div#error`).hide();
//handling login form.
$("#login-form").submit(function(e){
    if($('#user').val() != "" && $('#psw').val() != "" && $('#npsw').val() != "") {
        $.ajax({
           type: "POST",
           url: "login-process.php",
           data: $("#login-form").serialize(),
           success: function(response){
               $('#login-form')[0].reset();
               console.log(response);
               if (response == "True") {
                   window.location.href = "info.php";
               }
               else {
                       $(`div#error`).show();
               }
           }
         });
     }
     else {
         alert("Please fill the fields.")
     }
    e.preventDefault();
});

The problem: The div popup is showing on the page and it's not hidden. When I close it manually from the close button. Handler is not showing the div if the data is incorrect.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Set the display as none on page load for the error div

<div id="error" class=" col-sm-3  mx-auto  mt-4 alert alert-danger alert-dismissible fade show" role="alert" style="display:none">
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda