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

249
Views
How to change element attribute on toggle with Javascript?

I would like to add attribute "aria-label=test1" when it is fa-chevron-left and "aria-label=test2" on fa-chevron-right.

"aria-label=test1" should be there on load (default). Could anyone show me how to code it for here?

function s(e) {
  const t = n(),
    c = document.querySelector(".nav-container"),
    o = document.querySelector(".content-container"),
    s = document.querySelector(".slide-btn i.fas");
  switch (e) {
    case "toggle":
      c.classList.toggle("slided"),
        s.classList.toggle("fa-chevron-right"),
        s.classList.toggle("fa-chevron-left"),
        t && o.classList.toggle("slided");
      break;
    case "show":
      c.classList.remove("slided"),
        s.classList.remove("fa-chevron-right"),
        s.classList.add("fa-chevron-left"),
        t && o.classList.add("slided");
      break;
    case "hide":
      if (c.classList.add("slided"), s.classList.add("fa-chevron-right"), s.classList.remove("fa-chevron-left"), t) {
        o.classList.remove("slided");
        const e = document.querySelector(".body-container").getAttribute("activeTopic");
        document.getElementById(e).scrollIntoView()
      }
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could do :

element.setAttribute("aria-label", element.classList.contains("fa-chevron-left") ? "test1" : "test2");
about 4 years ago · Juan Pablo Isaza Report
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!