DOM Creating content
Create Content
You can create a div element an set the content.
We use the document method createElement and the DOM node method appendChild
let e = document.createElement('div'); e.innerHTML = 'Hello'; document.body.appendChild(e);
let e = document.createElement('div'); e.innerHTML = 'Hello world'; document.body.appendChild(e);
Create img
You can create a img element an set the src.
We use the document method createElement and the DOM node method appendChild and the node property innerHTML
let a = document.createElement('img'); a.src = '/flags/fr.png'; document.body.appendChild(a);
let a = document.createElement('img'); a.src = '/flags/fr.png'; document.body.appendChild(a); let e = document.createElement('div'); e.innerHTML = 'France'; document.body.appendChild(e);