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

138
Vistas
Css visibility hidden

I'm trying to create a toggle button through javascript without a button ID and the css element visibility hidden, I have been trying to google it but can't find any good answers, I can only found how you toggle by using style.display but that doesn't work when I use visibility hidden in css. The button name for the toggle button is button2 and the hidden button has Hbutton as the ID.

document.querySelector(button8).addEventListener(click, function () {
  document.querySelector("hiddenbutton").style.visibility = "visible";
});
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Get the current style, and use a conditional.

document.querySelector(button8).addEventListener(click, function() {
  const button = document.querySelector("hiddenbutton");
  let current = getComputedStyle(button).getPropertyValue("visibility");

  button.style.visibility = current == "visible" ? "hidden" : "visible";
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use the computed style to determine whether or not the element is visible.

document.querySelector("button").addEventListener("click", function(){
  let p = document.querySelector("p");
  let visibility = getComputedStyle(p).visibility;
  if(visibility == "hidden")
    p.style.visibility = "visible";
  else
    p.style.visibility = "hidden";
});
p
{
  visibility: hidden;
}
<p>I will disappear</p>
<button>Toggle</button>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can actually do this by toggling through classes which is more simple! Just create a class e.g. .hide and set the visibility to hidden. Whenever you click on the button, the selected button's class will be toggled through the given class(.hide).

document.querySelector('.toggle').addEventListener('click', () => {
  document.querySelector('.myBtn').classList.toggle('hide');
});
.hide {
  visibility: hidden;
}
<button class="myBtn">You See Me!</button>
<button class="toggle">toggle</button>

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