Question 2
Back to Exercise
The page contains this HTML:
<p id="msg">Hello <b>World</b>!</p>What does the following JavaScript code print when it runs on this page?
const msg = document.getElementById("msg");
console.log(msg.textContent);
console.log(msg.innerHTML);
- A Hello <b>World</b>! Hello World!
- B Hello World! Hello World!
- C Hello World! Hello <b>World</b>! Correct
- D Hello ! Hello <b>World</b>!
Correct Answer: Option C
textContent joins all the text of the descendants; innerHTML serialises the markup.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!