Question 12
Back to Exercise
The page contains this HTML:
<ul id="a"><li>One</li><li>Two</li></ul><ul id="b"></ul>What does the following JavaScript code print when it runs on this page?
const a = document.getElementById("a");
const b = document.getElementById("b");
const first = a.firstElementChild;
b.append(first);
b.append(first);
console.log(a.children.length, b.children.length, b.textContent);
- A 1 1 One Correct
- B 2 2 OneOne
- C 2 1 One
- D 1 2 OneOne
Correct Answer: Option A
A node can be in only one place: append moves it out of #a, and appending it again to the same parent changes nothing. Use cloneNode to copy.
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!