+ 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.
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
+ 3
Think of innerHTML as the content of the tag.