+ 2
I don't understand the essence of the innerHTML
5 Respostas
+ 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
+ 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"
0
html
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>
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