0

Having this issue everytime I try to access the .style property. This happens everytime I try to modify the CSS properties using .style in javascript.

code.js:9 Uncaught TypeError: Cannot read property 'style' of undefined at HTMLImageElement.

for(var i = 0; i<description.length;i++) {
  image[i].addEventListener("mouseover", function() {
    description[i].style.visibility = visible;
    description[i].style.opacity = 0;
    var last = +new Date();
    var tick = function() {
      description[i].style.opacity = +description[i].style.opacity + (new Date() - last)/700;
      last = +new Date();

      if (+description[i].style.opacity < 1) {
        (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16);
      }
    };

    tick();
  });
}
P.S.
  • 15,970
  • 14
  • 62
  • 86
John A
  • 83
  • 1
  • 3
  • 12
  • You shouldn't define functions within a loop, `i` will be `descriptions.length + 1` in every one of your event handlers – Rob M. Aug 04 '17 at 22:46
  • where did you define `description`? – P.S. Aug 04 '17 at 22:46
  • Right above that function using getElementsByClassName so I naturally just looped through all of them so they would all do the same event – John A Aug 04 '17 at 22:51

0 Answers0