Creating elements

Creating elements goes through document.createElement to build a node, which you configure then insert into the page with append, prepend, or before. This method avoids assembling HTML as text and protects against injections. remove() deletes an element.

Example

const li = document.createElement('li')
li.textContent = 'New task'
liste.append(li)

Related concepts

The whole glossary