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

185
Visualizações
JS Toggle but default value as hidden

Here is the HTML/JS I am using. Right now, the toggle works, but the default value of the input text box is showing. I want the default value to be hidden, and then show when clicked. I tried adding display:none as styles to the input box, but then it stopped showing when clicked. Any idea what I am doing wrong?

const searchIcon = document.getElementById("search_icon");
  //toggle shows/hides search bar upon clicking search icon
function toggle(){
  const searchBox = document.getElementById("text-box");
  if (searchBox.style.display === "none") {
    searchBox.style.display = "block";
  } else {
    searchBox.style.display = "none";
  }
}
<div style="display:flex; align-items: center;">
    <span class="et_pb icon_wrap">
        <span class="et-pb-icon" id="search_icon" style="font-size: 20px;" onClick="toggle()">U
     </span>
    </span>
    <div id="text-box" style="padding-left: 5px;">
        <input type="text" name="s" placeholder="" class="et_pb_s" >
    </div>
</div>

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

0

Is this what you want? When you get the DOM node, you should directly get the input itself, not its parent div view

toggle(){
      const searchBox = document.getElementById("myInput");
      searchBox.placeholder = "you get me"
    }
        <input type="text" name="s" placeholder="" class="et_pb_s" id="myInput" >
  

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