I am new to JavaScript, and to stack overflow, so excuse me if I am being oblivious. I was trying to built a progress bar for several classes with the same class name:
<div class="skill">
<h4>Javascript</h4>
<div class="progress-bar" data-label="Loading..." style="--width: 10">
</div>
</div>
<div class="skill">
<h4>Wordpress</h4>
<div class="progress-bar" data-label="Loading..." style="--width: 10">
</div>
<div class="skill">
<h4>Java</h4>
<div class="progress-bar" data-label="Loading..." style="--width: 10">
</div>
</div>
<div class="skill">
<h4>Bootstrap</h4>
<div class="progress-bar" data-label="Loading..." style="--width: 10">
</div>
but the JavaScript code:
const progressBar = document.getElementsByClassName
('progress-bar')[0]
setInterval(() => {
const computedStyle = getComputedStyle(progressBar)
const width = parseFloat(computedStyle.getPropertyValue
('--width')) || 0
progressBar.style.setProperty('--width', width + .1)
},5)
was applied only to the first class:
<h4>Javascript</h4>
<div class="progress-bar" data-label="Loading..." style="--width: 10">
</div>
Where did I go wrong? Thank you for your time.