Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Level 10 lesson 4 code

Anyone got the code for level 10 lesson 4?
This is my code but the system is telling me that I'm using the wrong div tag. Any help will be appreciated. Thanks!

<!doctype html>
<html>
<head>
<title>Modify HTML Element in JS</title>
</head>
<body>
<h1 id="heading">This is a heading</h1>
<p>Then comes a paragraph or a bunch of paragraphs.</p>
<p>So let's add another paragraph.</p>
<div class="parentDiv">
<div class="childDiv">Hello JS!</div>
<div class="childDiv">Hello JS again!</div>
</div>
<hr/>
<script>

document.getElementById("heading").innerText = "My Webpage";
document.getElementsByClassName("parentDiv").innerHTML = "<b>I am learning JS</b>";

</script>
</body>
</html>
by

1 Answer

kshitijrana14
Try this one

<!doctype html>
<html>
<head>
<title>Modify HTML Element in JS</title>
</head>
<body>
<h1 id="heading">This is a heading</h1>
<p>Then comes a paragraph or a bunch of paragraphs.</p>
<p>So let's add another paragraph.</p>
<div class="parentDiv">
<div class="childDiv">Hello JS!</div>
<div class="childDiv">Hello JS again!</div>
</div>
<hr/>
<script>
// change heading text
document.getElementById("heading").innerText="My Webpage";

// change HTML code inside childDiv element
document.getElementsByClassName("childDiv")[1].innerHTML="<b>I am learning JS</b>";

</script>
</body>
</html>

Login / Signup to Answer the Question.