+ 2

Can you please say What does the innerHTML property do?

While passing a JavaScript course, I encountered the innerHTML property, but I still do not understand what it does.

2nd May 2019, 10:46 AM
Kinito'S
Kinito'S - avatar
2 Respostas
+ 9
innerHTML of an html element contains the html tags and text enclosed with the tags of that element. Example: <html> <body> <div id="container"> <p>Hi!</p> </div> </body> <script> onload = () => { console.log(container.innerHTML); } </script> </html> Will print in the console the html code enclosed with div tag with the id = "container": <p>Hi!</p> you could use it to manipulate html dinamically
2nd May 2019, 11:14 AM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 3
Think of innerHTML as the content of the tag.
2nd May 2019, 12:04 PM
BlackSmithOP
BlackSmithOP - avatar