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

300
Visualizações
How do I toggle aria-expanded whilst also changing content and hiding element?

Using vanilla JS, I'm trying to toggle the visibility of an element and then change the text of the button whilst also changing the aria-expanded.

If you click on the button, then the list should show as-well as the button changing text, and if you click on it again, then the list will be hidden as-well as the button text changing.

Below is the code but can't seem to figure out why it's not working?

  var featureListToggleButton = document.getElementById(
    "FeatureList-toggle-button"
  );
  var featureList = document.getElementById("FeaturesList");

  featureListToggleButton.addEventListener("click", function () {
    featureListToggleButton.getAttribute(
      "aria-expanded",
      function (index, value) {
        var isExpanded = value === "true";
        featureList.classList.toggle("hide");
        featureListToggleButton.textContent(isExpanded ? "Show" : "Hide");

        return !isExpanded;
      }
    );
  });
about 4 years ago · Juan Pablo Isaza
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