Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!