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

137
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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