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

306
Views
why I can't add class to div on scroll using this code in Javascript.I searched on google but i can find it only by jquery which I dont understand

why I can't add class to div on scroll using this code in Javascript.I searched on google but i can find it only by jquery which I dont understand.

var pbar = document.getElementsByClassName("bar_ani");
    window.onscroll = function () {
        if (window.scrollY > 20) {
            pbar.classList.add("animate-scroll");
        }
    }
.animate-scroll{
    animation: progress 0.5s ease linear;
}
@keyframes progress {
    from{
        width: 0%;
    }
}
<div class="progress">
  <div class="progress_bar bar_ani" role="progressbar"  style="width: 90%;background-color:cyan" aria-valuenow="70" aria-valuemin="0" aria-valuemax="70">
  </div>
 </div>

strong text

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

document.getElementsByClassName("bar_ani")

returns an array, so you should use pbar[0].classList.add() instead of pbar.classList.add().

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!