DEV Community

Discussion on: What's your preferred method for inserting DOM elements in vanilla JS?

Collapse
 
karataev profile image
Eugene Karataev

Handling complex DOM manipulations with vanillaJS is tough.
For simple cases I use createElement() and fullfill the element with innerHTML:

let title = 'DOM Manipulation';
let description = '🤔';
let el = document.createElement('div');
el.innerHTML = `
<h1>${title}</h1>
<p>${description}</p>
`;
document.body.appendChild(el);