how can i get <p> tag value of html in JavaScript console? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how can i get <p> tag value of html in JavaScript console?

i am trying to print the paragraph tag value 'hello' in html using JavaScript console. how can i do that? https://code.sololearn.com/WPE75Fhs2d63/?ref=app

24th Aug 2020, 4:20 PM
Mr. 12
Mr. 12 - avatar
3 Answers
+ 2
Add a onload event listener in which you call your function. Otherwise the functions runs before the HTML is loaded and the p element with id "h" can't be found by the JavaScript.
24th Aug 2020, 4:29 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 2
Mr. 12 use the following code: function myCal(){ return document.getElementById("h").innerHTML; } window.onload = () => { console.log(myCal()); };
24th Aug 2020, 5:44 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
0
Aaron Eberhardt i didn't get it bro
24th Aug 2020, 5:10 PM
Mr. 12
Mr. 12 - avatar