Skip to content
Advertisement

Error code “Uncaught TypeError: Cannot read property ‘style’ of null” in my javascript code

I am using a for(){} statement to loop through every element I have in order to change the text color and remove underlining when a function is called. After doing so, the function will then set the font color and underline the selected text. However, I keep receiving the error message Uncaught TypeError: Cannot read property 'style' of null. I triple-checked My element’s names, making sure that they were right. They were.

JavaScript

The code above is what I have currently. The code underneath the second comment works.

Advertisement

Answer

I guess because of i = -1 in for loop the problem occurs:

So, try with the below code:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement