196
rated 0 times
[
200]
[
4]
/ answers: 1 / hits: 28559
/ 11 Years ago, wed, february 26, 2014, 12:00:00
I've been trying to change the width of a div with a set.interval animation. It works perfectly fine with getELementByID, but it won't work with getElementsByClassName.
The code is the following:
var loadingBar = 200;
function animationBarOne(){
document.getElementsByClassName(loading-bar).style.width=(loadingBar+px);
loadingBar++;
if(loadingBar === 900){
clearInterval(intervalId);
}
}
var intervalId = setInterval(animationBarOne,1);
I'm getting can't set property width of undefined. As I said it works perfectly with ID, but giving I have like 10 bars to animate I rather use class name so its cleaner.
Thanks in advance.
More From » javascript