I want to Access the heading and display it in console. I have error. Thanks you. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I want to Access the heading and display it in console. I have error. Thanks you.

Display heading in a console. https://code.sololearn.com/WHi9TINlqdal/?ref=app

20th Jan 2021, 5:04 AM
Malick Diagne
Malick Diagne - avatar
2 Answers
+ 1
Your JavaScript code got executed before the <h1> is loaded, so it return error since it didn't find <h1> in the page. So, you can run the JS after the page is loaded using onload() like in this example. https://code.sololearn.com/WTHHEukxmtzZ/?ref=app Or you can paste the JavaScript code at the end of your body tag.
20th Jan 2021, 5:12 AM
Bibek Oli
Bibek Oli - avatar
+ 1
In JS tab window.onload = function(){ //Always put your JS code here. }
20th Jan 2021, 5:13 AM
Vadivelan