Question 14
Back to Exercise
The page contains this HTML:
<div id="card" class="card"><h3>Quiz</h3></div>What does the following JavaScript code print when it runs on this page?
const card = document.getElementById("card");
const shallow = card.cloneNode();
const deep = card.cloneNode(true);
console.log(`[${shallow.textContent}]`, shallow.className, deep.textContent, deep.isConnected);
- A [] card Quiz false Correct
- B [Quiz] card Quiz true
- C [] undefined Quiz false
- D [Quiz] card Quiz false
Correct Answer: Option A
cloneNode() copies the element and its attributes only; cloneNode(true) copies the children too. Clones are not on the page until you insert them.
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!