Message from JavaScript discussions

March 2019

— DOM API is better

— 

const div = document.createElement('div');
div.textContent = 'Name: ' + person[0].name;
document.body.appendChild(div);

— Like this

— I know inner HTML is better but it is explicitly mentioned to use document.write

— And am getting error

— Error

— TextContent is better*

— Try this bri

— Bro

— Ok let me try

— Works

— const person = [ { name: 'Thomas' } ];
const div = document.createElement('div');
div.textContent = 'Name: ' + person[0].name;
document.body.appendChild(div);

Message permanent page