Cannot read property 'addEventListener' of null Error, not sure why

前端 未结 2 430
误落风尘
误落风尘 2021-01-27 05:16

Whenever I hover over the image it does not enlarge and gives an error.

HTML and Javascript code(these are two separate files):

var banner = document.ge         


        
相关标签:
2条回答
  • 2021-01-27 06:01

    Your javascript code is in your first section. So it has rendered before banner element and cannot find the element id = banner because it has not rendered yet. Try to locate the code before the html code.

    0 讨论(0)
  • 2021-01-27 06:03

    When referencing the function normalpic, you should preceed it with an empty function:

    banner.addEventListener("mouseout",function(){normalpic},false)
    
    0 讨论(0)
提交回复
热议问题