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

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