1. Home
  2. Javascript
  3. Create element

Create and append HTML element. In the example an empty paragraph is being created using createElement property. Then the content is added through innerHTML property and finally the new element is appended to the body.

#javascript
var el = document.createElement("p");
el.innerHTML = "Content of the new element";
document.body.appendChild(el);
copy
Full Javascript cheatsheet