Hi @doriodavid. I think your problem is in the line below:
let newChild = document.createElement('h1').appendChild(document.createTextNode('Hello World'))
According to MDN, appendChild
returns the appended child. For example if you invoke it like element.appendChild(aChild)
, it returns aChild
which is 'Hello World'
for your case and you are assigning it to newChild
. Essentially you are replacing the h1
element with the text 'Hello World'
. If you click the button the second time, you get an error because there is no h1
element any more. Try using the devTool after clicking the button once. You will see what I am talking about. You will remove the error if you do the following:
let newChild = document.createElement('h1');
let textNode = document.createTextNode('Hello World');
newChild.appendChild(textNode);