How to fix Cannot read property 'addEventListener' of undefined Error in JavaScript?
Cannot read property 'addEventListener' of undefined is the most frequent error we see when developing a client-side application with the help of JavaScript. Fixing this error requires you to understand further this error. So it's first important to know what causes this error. Actually, It occurs when your script code calls an external function that has not been defined in your code. This is caused due to improper use of the development tools. Here we have listed some useful steps to solve this problem:
Also Check these Questions:
How to Fix Uncaught TypeError is not a Function?
uncaught TypeError: $ is not a function
window addeventlistener
Uncaught TypeError: Cannot read property 'addEventListener' of undefined
1)Check you placed .before the class
Example:
document.getElementsByClassName('.yourclassname') //.before class name is wrong
the code should be document.getElementsByClassName('yourclassname');
2)Check the spelling for addEventListener
///dont feel embrassed because i always do these mistakes eventhough i used this property it 10000 times
The most common cause of the above error is usually a conflict between jQuery and another JavaScript library on that page. Try the code mentioned above.