1

Please help, I just started to learn JS a month ago. Why the append is not showing in other same id?

const getName = prompt("May I know your name?");
document.getElementById("guest").append(getName);
<p>Hello, <span id="guest"></span>!</p>
<p>Your name is, <span id="guest"></span>.</p>

Thanks in advance!

  • 1
    Use classes instead (eg `class="guest"`) and something like `document.querySelectorAll(".guest").forEach((el) => { el.append(getName); });` – Phil Jul 04 '22 at 04:50

0 Answers0