I'm trying to figure out what is the differences between this two:
// first one
var h1 = document.createElement('h1');
var t = document.createTextNode('hey');
h1.appendChild(t);
document.body.appendChild(h1);
// second one
document.body.appendChild(document.createElement('h1').appendChild(document.createTextNode('hey')));
The first (Document.createElement()) works perfectly, but the second (Document.createTextNode()) does not.
appendChildreturns the appended node, so you're trying to append a text node to body...document.createElement('h1').appendChild(document.createTextNode('hey')is the text node ... therefore you are appending the text node to the body