0

function rpsGame() {
  var textAnswer = document.createTextNode('You chose a paper');
  document.getElementById('this').appendChild("textAnswer");
}
<img id="paper" src="./paper.jpg" height=150 width=150 onclick="rpsGame()"></div>
<div class="answer">
  <div id="this"></div>
</div>
</div>

The error I get is:

Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

I want it to show the text on the div called this.

Omri Attiya
  • 3,917
  • 3
  • 19
  • 35
sam
  • 11
  • 1
    The error message is quite clear. You're passing a string to `appendChild`, not the expected (text) node. – Bergi Oct 08 '20 at 09:59
  • Hey SirMatope, duplicate question just here : https://stackoverflow.com/questions/5677799/how-to-append-data-to-div-using-javascript hope it will help you – Virgile Junique Oct 08 '20 at 10:11
  • Typo: Variable names shouldn't have quotes around them. – Quentin Oct 08 '20 at 10:15

0 Answers0