I don't understand the essence of the innerHTML | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I don't understand the essence of the innerHTML

22nd Jun 2016, 10:47 PM
Ozii
Ozii - avatar
5 Answers
+ 8
<!DOCTYPE html> <html> <body> <p id="demo" onclick="change()">Click me to change my HTML content (innerHTML).</p> <script> function change() { document.getElementById("demo").innerHTML = "Paragraph changed!"; } </script> </body> </html> you should be clear by this now
23rd Jun 2016, 5:27 AM
Sumanth Reddy
Sumanth Reddy - avatar
+ 1
ob = document.getElementById(" "); .innerHTML = "Hi"; here the answer is first we declare "var", variable then go fo the id named, "text" and then we access the object by variable name, which is "ob"
9th Sep 2020, 12:54 PM
Nitin Singh Rawat
Nitin Singh Rawat - avatar
0
html
23rd Jun 2016, 6:12 AM
lizi
0
this is just built-in property, which refers to selected element's inner(between open and close tags) html content. So if you assign something to it it will appear on the page. <p></p> <script> var p = document.getElementsByTagName ("p")[0]; p.innerHTML = "hi there!"; </script>
26th Oct 2016, 8:41 PM
Iaroslav Kalytiuk
Iaroslav Kalytiuk - avatar
0
All that innerHTML does is replace (literally) everything inside its target, or just place, if its target is empty. For example: // target <div class="target"> Hey, I'm a little sentence inside a div </div> //Button that triggers the innerHTML action <input class="inner-btn" type="button" onclick="performInner( )"/> // JavaScript section Function performInner ( ) { let el = document.querySelector("target"); el.innerHTML = "You did it!"; } All we have done here is just change the "target" content via innerHTML. I hope I was helpful
9th Jan 2018, 1:43 AM
Caio Chiquetto
Caio Chiquetto - avatar