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

186
Vistas
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 Respuestas
Responde la pregunta

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 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