Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
How to not hide my form element after submission if its css display style was set to none previously

$(()=>{

    $("#c").click(function loop(event){

        $("#a").show(1000).submit(function(event){

            if ($("#b").val() === "hello"){

                    $("#a").hide(1000);

                }

            else{
                
                    alert($("#b").val() + " was typed!");
            }
        });
    });
});
    #a{
        display: none;
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="a"> name : <input type="name" id="b" value="type 'hello' to hide!"></form>
    <button id="c">do it!</button>

In the above snippet I don't want the input box to disappear from screen when anything other than hello is typed! It should display the message $("#b").val() + " was typed!" but shouldn't hide.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hope this helps.

It was not actually hidden, rather the DOM itself was removed.

$(()=>{

    $("#c").click(function loop(event){

        $("#a").show(1000).submit(function(event){

            event.preventDefault();

            if ($("#b").val() === "hello"){

                    $("#a").hide(1000);

                }

            else{
                
                    alert($("#b").val() + " was typed!");
            }
        });
    });
});
    #a{
        display: none;
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="a"> name : <input type="name" id="b" value="type 'hello' to hide!"></form>
    <button id="c">do it!</button>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda