0

Why is my code for getElementsByClassName not working? It works when using getElementById but not with a class? I am using the TweenLite extension.

my code that does not work- http://codepen.io/bleubateau/pen/pvbeaO the same code that works with ID- http://codepen.io/bleubateau/pen/ogLZqb similar code that does work with the class- http://codepen.io/bleubateau/pen/PwzpQj

window.onload = function() {
  var play = document.getElementById("lay");

play.onmouseover = function(){
    TweenMax.to(play, 0.5, {width:"120px", marginLeft:"-60px", marginTop:"-60px", repeat:-1, repeatDelay:0.1, yoyo:true});

};

play.onmouseout = function(){
    TweenLite.to(playBTN, 1, {width:"100px", marginLeft:"-50px", marginTop:"-50px"});
};
}
Kay
  • 95
  • 12

1 Answers1

3

getElementsByClassName() generates a node list, so even if your list contained only one item, you would still need to access it like so:

var play = document.getElementsByClassName('lay')[0];
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Marventus
  • 864
  • 1
  • 7
  • 14