In my project how do I fix the issue of console saying textContent cannot read? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In my project how do I fix the issue of console saying textContent cannot read?

Please refer to my Birthday Invitation Webpage project here on Sololearn and you will see on phone that when we press run the console says textContent cannot read which should not be a problem as it a function predefined in CSS.?? Why is this happening and how do I fix it? Pps help.

18th Dec 2020, 4:01 PM
Quantitanic
Quantitanic - avatar
2 Answers
+ 5
Use a event listener to run JavaScript when page loads It is showing error because the JavaScript is running before the window render the html, that means at time of execution of JavaScript there is no html element so it can't read textContent of null See the fixed code i have used an event listener to run the js when the page loads https://code.sololearn.com/WjPa7Jqp8pf5/?ref=app
18th Dec 2020, 4:09 PM
Arnav Kumar [Less/Not Active]
Arnav Kumar [Less/Not Active] - avatar
+ 1
Thank you
19th Dec 2020, 2:26 AM
Quantitanic
Quantitanic - avatar